Reputation: 33
I want to use SymPy to create a Polygon with n faces and calculate all parameters.
The easy form is
from sympy import Polygon
p1, p2, p3, p4, p5 = [(0, 0), (1, 0), (5, 1), (0, 1), (3, 0)]
Polygon(p1, p2, p3, p4, p5)
Polygon(Point(0, 0), Point(1, 0), Point(5, 1), Point(0, 1))
but I want to use n points from a list, for example
p = [(0, 0), (1, 0), (5, 1), (0, 1), (3, 0)]
Polygon(p)
But this form and similar is not validated.
Any suggestions?
Upvotes: 3
Views: 1359
Reputation: 410
You could do this by putting an asterisk in front of the list of parameters to expand it out, like so:
p=[(0, 0), (1, 0), (5, 1), (0, 1), (3, 0)]
Polygon(*p)
This will be equivalent to calling Polygon((0, 0), (1, 0), (5, 1), (0, 1), (3, 0))
.
Upvotes: 4