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:
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.)
Theorem 39: If a convex polygon has n sides, then its interior angle sum is given by the following equation: S = ( n −2) × 180°.
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.
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.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With