# 2D OBB SAT questions

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

## 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 on other sites
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 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 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 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 on other sites

thanks! that was all extremely helpful.

1. 1
Rutin
67
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633418
• Total Posts
3011786
• ### Who's Online (See full list)

There are no registered users currently online

×