Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convex Decomposition of a Complex Polygon?

With both my 2D physics system (box2D) and OpenGL, conplex polygons need to be decomposed into convex polygons. Ensuring models conform to this is easy. However, I would also like to edit the polygons as the simulation progresses, so I need a dynamic way of fracturing existing polygons into more polygons that are still convex.

I hope this drawing helps describe what I'm after:

image aid

My Question is, Is there an existing library that can accomplish this? And if not, what would be the least error prone way of doing it myself?

(I was looking through Boost, which has both a Geometry and a Polygon module, but the documentation is proving a little too esoteric for me to know if either can do what I want.)

like image 487
Anne Quinn Avatar asked Oct 10 '11 01:10

Anne Quinn


People also ask

What is the formula for a convex polygon?

Theorem 39: If a convex polygon has n sides, then its interior angle sum is given by the following equation: S = ( n −2) × 180°.

What is a convex Ngon?

A strictly convex polygon is a convex polygon such that no line contains two of its edges. In a convex polygon, all interior angles are less than or equal to 180 degrees, while in a strictly convex polygon all interior angles are strictly less than 180 degrees.

What are convex polygons examples?

Real-world examples of convex polygons are a signboard, a football, a circular plate, and many more. In geometry, there are many shapes that can be classified as convex polygons. For example, a hexagon is a closed polygon with six sides.

What is the difference between convex and nonconvex polygons?

A polygon is convex if all the interior angles are less than 180 degrees. If one or more of the interior angles is more than 180 degrees the polygon is non-convex (or concave).


1 Answers

I think this is what you're looking for.

As for finding the intersection, that's just a little algebra; for any two line segments it's easy to derive the corresponding lines ('rise over run', etc.),

y = a1*x + b1

y = a2*x + b2

then the point of intersection (x', y') is

x' = (b2 - b1) / (a1 - a2)

y' = a1*x' + b1

Now of course that's the point of intersection of the lines, to determine that the line segments actually intersect you'll need to do simple range checking with the x, y coordinates.

like image 194
Matt Phillips Avatar answered Nov 08 '22 01:11

Matt Phillips