简体   繁体   English

旋转矩形边框尺寸

[英]Rotated rectangle bounding box size

If I have a given rectangle, with the width w , height h and angle r 如果我有一个给定的矩形,其宽度为w ,高度为h ,角度为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 我需要它来为我正在制作的2D物理引擎执行快速边界框检查

this may be what you need: 这可能是您需要的:

Calculate Bounding box coordinates from a rotated rectangle , answered by someone named markus. 根据一个旋转的矩形计算边界框坐标,该矩形由名为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 实际上,您可以使用角度阈值来决定使用圆形还是考虑原始矩形(大多数退化情况是当角度接近k*PI且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) . 如果您真的很想考虑旋转的矩形,则可以通过选择矩形的最高顶点(xT, yT)和最左边的(xL, yL) (当然是旋转后)来轻松计算出它的最左上角是(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. 然后,您对矩形的最右端和最低点取右下角(xR, yB)进行相同的操作,就可以了。 It will be the rectangle included in (xL, yY) (xR, yB) . 这将是(xL, yY) (xR, yB)包含的矩形。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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