r/gamedev • • Jun 25 '14

Question about 2D polygon angle simplification

I've been looking up some ways to change the red polygon into the blue polygon in this diagram. You'll notice that the new blues angles are all multiples of 15°. I don't mind degeneration of the original polygon and the "corrections" can be iterative or simultaneous. I need it for level generation if that helps. The final polygon can be concave or convex, no problems. I think the Ramer-Douglas-Peucker algorithm (a polygon simplification algorithm) could be useful somehow, but maybe there's something else I don't know about. Can anyone push me in the right direction? What do we call this problem? Thanks a lot!

5 Upvotes

17 comments sorted by

View all comments

Show parent comment

1

u/simswerdev Jun 26 '14

Wow, cool, hi Randy. Love your tutorials.

If I'm understanding you correctly, you're saying this is without a doubt a constraints problem (opening up that can of Jacobian-Lagrangian worms I have not yet been able to swallow, only nibble at).

I've been scrumming with this for a while and I've been able to reduce the problem to this question I posed on Stack Exchange Math. It might not have a solution though, unless I'm missing something.

I've wondered myself if it wouldn't be possible to chop up the edges into limited lengths, then "snap" the angle between the two edges. That way the edge length error becomes insignificant and the polygon "gains" an extra vertex or two (no biggy for me). Or do I sound like an embarrassing idiot here?

Love wrestling with these things, damn!

2

u/RandyGaul @randypgaul Jun 26 '14

You can definitely just snap the vertex to a 15 degree boundary by moving it. I don't think any forces, jacobians or lagrangians are necessary here. Looks like you got a very nice answer on the mathexchange!

1

u/simswerdev Jun 27 '14

Cool, thanks! Yeah the Stack Exchange answer is very useful. I've made some headway. Almost there (I hope).