🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Polygons and the Separating Axis Theorem

Started by
12 comments, last by Randy Gaul 5 years, 8 months ago
8 hours ago, Seer said:

I suppose I'm thinking of the bounding rectangle of the polygon. When a polygon object is made, vertices are placed around the polygon according to the sin and cos of the rotation given and its half width and half height. I just want to make it so that no matter the rotation affecting the initial placement of the vertices, that the width and height of the polygon (along the X and Y axes) are the same as those given in the constructor. Can you see a way to do this?

It sounds like you want to apply a (possibly non-uniform) scaling to a regular polygon so that its axis-aligned bounding box has dimensions that you specify. This is sort of the reverse of what's more commonly done (creating a bounding box to fit a shape), and will likely stretch or compress the polygon with respect to its natural shape (but maybe that's the goal).

Here's a solution that comes to mind. Build the polygon in 'neutral' form, say, with a radius (distance from the center to any vertex) of 1. Compute the bounding box of the polygon in that form. Then compute scale factors as:


scale_x = desired_bounding_box_width / computed_bounding_box_width
scale_y = desired_bounding_box_height / computed_bounding_box_height

And apply the scaling to the polygon vertices. (This would all be done in local space with the polygon centered at the origin.)

I haven't tried this myself, so I can't guarantee I've gotten the details right. What I described should be fairly easy to implement though, so you might try it and see if it's what you're looking for.

I'll also add:

Quote

While this places the vertices at the correct angle around the polygon, the problem is that if the rotation is anything other than 0, the width and height of the polygon are no longer the values specified.

I'd think that in the general case, even if the rotation were 0, you still wouldn't be guaranteed to get a bounding box with the specified dimensions.

Advertisement

Hi,

A detailled explanation of SAT, which might help.

http://www.dyn4j.org/2010/01/sat/

Best regards

Projecting is more or less outdated in favor of support points. See Dirk's GDC lecture hosted on box2d.org on SAT for the best resources. Typically when someone pops into this forum using old project methods they will immediately get directed to Dirk's lecture...

This topic is closed to new replies.

Advertisement