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