Ask Your Question
3

How to triangulate polygon with sage?

asked 13 years ago

Bill gravatar image

If I feed sage a list of vertices, then the polygon() function can create a 2D polygon determined by visiting these edges in order (with self-intersections, repeated edges, holes, etc.).

Does sage have a built-in method to triangulate the resulting polygon? (It appears to me as though this is not the case.)

If not, I would love to see your homemade code to do this.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
5

answered 13 years ago

Volker Braun gravatar image

The polygon() function is for plotting, not for polyhedral computations. You can do the following:

sage: square = Polyhedron([(0,0), (1,0), (0,1), (1,1)])
sage: square
A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 4 vertices
sage: square.triangulate()
(<0,1,3>, <0,2,3>)

If you are more serious about triangulations, this should get you started. As usual, the online help is your friend if you want to know more:

sage: pc = PointConfiguration([(0,0), (1,0), (0,1), (1,1)])
sage: pc
A point configuration in QQ^2 consisting of 4 points. The triangulations of this point configuration are assumed to be connected, not necessarily fine, not necessarily regular.
sage: pc.triangulations_list()
[(<0,1,2>, <1,2,3>), (<0,1,3>, <0,2,3>)]
Preview: (hide)
link

Comments

Thanks for the suggestion. Unfortunately, I am working in a setting where taking the convex hull of the vertices of my polygon is not what I want to do. (My polygons have holes in them.)

Bill gravatar imageBill ( 13 years ago )

I don't think Sage has anything for non-convex polygons. One should implement Chazelle's algorithm, I suppose (http://wiki.xomb.org/images/0/09/Chazelle_PolygonCutting.pdf)

Volker Braun gravatar imageVolker Braun ( 13 years ago )

I will look at that algorithm. Thanks.

Bill gravatar imageBill ( 13 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 13 years ago

Seen: 1,133 times

Last updated: Apr 05 '12