Jump to content
  • Advertisement
Sign in to follow this  
drvannostrand

2D OBB SAT questions

This topic is 4392 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm pretty clear on how the SAT works, but I'm getting confused doing an implementation. In all the posts I can't seem to find how the rotation of the OBB is worked into it. First, lets say I want to represent my 2D box:
Vector2 center;
float extents[2];
float orientation;
Is that enough? Do the extents always remain the same? Don't I need something else to allow for the rotation/orientation when I project the box onto an axis? For example, in a post by JYK, he has the following code:
float radius =
    box_extents[0]*fabs(axis.Dot(box_axis[0]))+
    box_extents[1]*fabs(axis.Dot(box_axis[1]));
What part of this has the rotation/orientation of the box worked into it? And how is that done?

Share this post


Link to post
Share on other sites
Advertisement
Assuming your "orientation" value is in radians, then c = cos(orientation), s = sin(orientation), box_axis[0] = (c,s), and box_axis[1] = (-s,c).

Share this post


Link to post
Share on other sites
I'm assuming 'float orientation' is intended to be the angle of rotation of the box. This is fine, but for most useful OBB queries you'll need to represent the box's orientation using an orthonormal basis. This basis can also be thought of as the local axes or the oriented box.

The extents always remain the same, regardless of orientation (unless of course you want to change the shape of the box). In the above code sample, box_axis[] is an array of two 2D vectors representing the box's local axes. (In 3D it would be an array of three 3D vectors.)

The axes can be constructed from the orientation angle as follows:
float s = sin(orientation);
float c = cos(orientation);
axis[0].set(c,s);
axis[1].set(-s,c);
'Hope that helps clear things up.

Share this post


Link to post
Share on other sites
Ok, thanks it's starting to clear up.

I would prefer to do it the right way and use an orthonormal basis. I'm not familar with that term though. You're saying it's the two 2D vectors representing the box's local axes?

Also, I'll still need to derive the corners in order to draw the rectangle. What's the best way to do that?

Share this post


Link to post
Share on other sites
Quote:
I would prefer to do it the right way and use an orthonormal basis. I'm not familar with that term though. You're saying it's the two 2D vectors representing the box's local axes?
An orthonormal basis consists of N mutually perpendicular unit-length vectors in RN. The local axes of a coordinate system (such as that of an OBB in 2D or 3D) are an example of an orthonormal basis.
Quote:
Also, I'll still need to derive the corners in order to draw the rectangle. What's the best way to do that?
The four corners of a 2D OBB can be found as:
corner = center +/- axis[0]*extents[0] +/- axis[1]*extents[1]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!