2D OBB SAT questions

Started by
4 comments, last by drvannostrand 17 years, 8 months ago
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?
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).
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.
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?
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]

thanks! that was all extremely helpful.

This topic is closed to new replies.

Advertisement