简体   繁体   中英

Rotated rectangle bounding box size

If I have a given rectangle, with the width w , height h and angle r

How large does another rectangle which contains all points of the rotated rectangle need to be?

I would need this to perform fast bounding box checks for a 2D physics engine I am making

this may be what you need:

Calculate Bounding box coordinates from a rotated rectangle , answered by someone named markus.

You usually should consider rotating rectangles in a collision detection engine, since it will be quite straightforward to implement (I mean considering the rotated rectangle as it is).

In any case if you really want to simplify to have a coarse-level of collision detection the best thing is to embed the rectangle inside a circle, because it's really simple (centered over rectangle center and with a radius of the semi-diagonal of the rectangle) and compared to using a box it can be quite accurate for a coarse detection. Actually you can have an angle threshold to decide if it's better to use a circle or to consider the original rectangle (most degenerating cases are when angle is near to k*PI with k = 0,1,2,3

If you really really want to consider the rotated rectangle you can calculate it easily by choosing the topmost vertex of your rectangle (xT, yT) and the leftmost (xL, yL) (after the rotation of course) to obtain the topleft point that will be (xL, yT) . Then you do the same thing for the bottomright corner taking (xR, yB) from the rightmost and lowest point of your rectangle and you have it. It will be the rectangle included in (xL, yY) (xR, yB) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM