如何获得旋转矩形的大小[复制]

时间:2022-01-22 21:28:20

Possible Duplicate:
Calculate Bounding box coordinates from a rotated rectangle, Picture inside.

可能的重复:从一个旋转的矩形计算边界框坐标,图像在里面。

I have a rotated rectangle, So how do i calculate the size of axis-aligned bounding box for the rotated rectangle in 2D Coordinates?

我有一个旋转的矩形,那么如何计算二维坐标下旋转矩形的轴向包围盒的大小?

Attach Image http://img88.imageshack.us/img88/503/rotp.png

附加图片http://img88.imageshack.us/img88/503/rotp.png

i know x, y, o (angle) but how do i get a, b

我知道x, y, o(角)但是我怎么得到a b。

Thank you

谢谢你!

7 个解决方案

#1


30  

a = abs(x * sin(o)) + abs(y * cos(o))
b = abs(x * cos(o)) + abs(y * sin(o))

#2


5  

To construct an axis-aligned bounding box, one must find the extreme points of the rotated box. i.e.,

要构造一个轴对齐的包围盒,你必须找到旋转盒子的极值点。也就是说,

given a rectangle 'P', given by points P1=(0,0), P2=(x,0), P3(x,y), P4(0,y), rotated 'R' degrees; find minX, maxX, minY, maxY, such that the box [(minX,minY),(maxX,maxY)] completely bounds the rotated 'P'.

给定一个矩形P,由点P1=(0,0), P2=(x,0), P3(x,y), P4(0,y),旋转R度;找到minX, maxX, minY, maxY,这样盒子[(minX,minY),(maxX,maxY)]完全限制旋转的P。

                          +-------P3'----+maxY
                          |     /    \   |
  P4------P3              |   /        \ |
   |      |    rotate     | /            P2'
   |      | => by 'R' =>  P4'           /|
   |      |    degrees    | \         /  |
  P1------P2              |   \     /    |
                          |     \ /      |
                          +-----P1'------+minY
                         minX           maxX

The values for the bounding box are the minimum/maximum of the components of the rotated points P1'..P4'; thus,

边界框的值是旋转的点P1'..P4的最小/最大值;因此,

minX=min(P1'[x],P2'[x],P3'[x],P4'[x])
maxX=max(P1'[x],P2'[x],P3'[x],P4'[x])
minY=min(P1'[y],P2'[y],P3'[y],P4'[y])
maxY=max(P1'[y],P2'[y],P3'[y],P4'[y])

For a discussion of 2D rotations, see http://en.wikipedia.org/wiki/Transformation_matrix#Rotation

有关2D旋转的讨论,请参见http://en.wikipedia.org/wiki/Transformation_matrix#旋转。

#3


1  

Well you didn't give a whole lot of detail. I'm assuming you know that the height and width of the rectangle will give you the area no matter the rotation. If you only have the x,y data points then you use the sqrt((x1-x1)^2 + (y1-y2)^2). To get the length of a side.

你没有给出很多细节。我假设你知道这个矩形的高度和宽度会给你这个区域的旋转。如果你只有x,y数据然后使用sqrt((x1-x1)^ 2 +(y1 y2)^ 2)。得到边的长度。

You clarified your question so if you have a rectangle and you know the angle from the top left corner is rotated away from the top so the left side looks like this.
  /
/
a = sine(alpha)*width
b = cosine(alpha)*width
c = sine(alpha)*height
d = cosine(alpha)*height

你澄清了你的问题,如果你有一个矩形,你知道左上角的角度是从上往下旋转的所以左边是这样的。/ / a = sin()*宽度b = cos()*宽度c = sin()*高d = cos (alpha)*高。

width = a + d
height = b + c
Be sure you get the angle right it is kind of hard to clarify it on here. If you get the other angle then it will come out to
width = b + c
height = a + d

宽度= a + d高度= b + c,确定角度是正确的这在这里很难解释。如果你得到另一个角,它就会出来,宽度= b + c高度= a + d。

#4


0  

For the axis aligned box of the rotated rectangle, you find the minimum and maximum of each of the 4 rotated coordintates. The minX and minY becomes 1 corner and the maxX and maxY becomes the other corner.

对于旋转矩形的轴对齐框,您可以找到四个旋转的coordintates的最小值和最大值。minX和minY变成了一个角,maxX和maxY变成另一个角。

#5


-1  

Calculate the area of the original rectangle. Area doesn't change under rotation.

计算原始矩形的面积。面积不会在旋转的情况下改变。

#6


-1  

Use [Heron's Formula Triangle Area Calculator] s = (a + b + c) / 2 or 1/2 of the perimeter of the triangle

使用[Heron的公式三角形区域计算器]s = (a + b + c) /2或三角形周长的1/2。

A = SquareRoot(s * (s - a) * (s - b) * (s - c))

Where

在哪里

a=SquareRoot((X1-X2)^2+(Y1-Y2)^2)  [Side 1 Length]
b=SquareRoot((X1-X3)^2+(Y1-Y3)^2)  [Side 2 Length]
c=SquareRoot((X2-X3)^2+(Y2-Y3)^2)  [Side 3 Length]

X1,Y1,X2,Y2,X3,Y3 are the coordinations of any three points (Corners)

X1,Y1,X2,Y2,X3,Y3是任意三个点的坐标

RectangleArea=2*A

Or Direct without [Heron's Formula Triangle Area Calculator], sequence of points are important here.

或者直接没有[Heron的公式三角区域计算器],点序列在这里很重要。

P1----P2
|     |
P3----P4

 a=SquareRoot((X1-X2)^2+(Y1-Y2)^2)  [Side 1 Length]
 b=SquareRoot((X1-X3)^2+(Y1-Y3)^2)  [Side 2 Length]
 RectangleArea=a*b

#7


-3  

It's a bit complicated, but for a rectangle, Area = b * h = length * width.

这有点复杂,但对于一个矩形,面积= b * h =长*宽。

#1


30  

a = abs(x * sin(o)) + abs(y * cos(o))
b = abs(x * cos(o)) + abs(y * sin(o))

#2


5  

To construct an axis-aligned bounding box, one must find the extreme points of the rotated box. i.e.,

要构造一个轴对齐的包围盒,你必须找到旋转盒子的极值点。也就是说,

given a rectangle 'P', given by points P1=(0,0), P2=(x,0), P3(x,y), P4(0,y), rotated 'R' degrees; find minX, maxX, minY, maxY, such that the box [(minX,minY),(maxX,maxY)] completely bounds the rotated 'P'.

给定一个矩形P,由点P1=(0,0), P2=(x,0), P3(x,y), P4(0,y),旋转R度;找到minX, maxX, minY, maxY,这样盒子[(minX,minY),(maxX,maxY)]完全限制旋转的P。

                          +-------P3'----+maxY
                          |     /    \   |
  P4------P3              |   /        \ |
   |      |    rotate     | /            P2'
   |      | => by 'R' =>  P4'           /|
   |      |    degrees    | \         /  |
  P1------P2              |   \     /    |
                          |     \ /      |
                          +-----P1'------+minY
                         minX           maxX

The values for the bounding box are the minimum/maximum of the components of the rotated points P1'..P4'; thus,

边界框的值是旋转的点P1'..P4的最小/最大值;因此,

minX=min(P1'[x],P2'[x],P3'[x],P4'[x])
maxX=max(P1'[x],P2'[x],P3'[x],P4'[x])
minY=min(P1'[y],P2'[y],P3'[y],P4'[y])
maxY=max(P1'[y],P2'[y],P3'[y],P4'[y])

For a discussion of 2D rotations, see http://en.wikipedia.org/wiki/Transformation_matrix#Rotation

有关2D旋转的讨论,请参见http://en.wikipedia.org/wiki/Transformation_matrix#旋转。

#3


1  

Well you didn't give a whole lot of detail. I'm assuming you know that the height and width of the rectangle will give you the area no matter the rotation. If you only have the x,y data points then you use the sqrt((x1-x1)^2 + (y1-y2)^2). To get the length of a side.

你没有给出很多细节。我假设你知道这个矩形的高度和宽度会给你这个区域的旋转。如果你只有x,y数据然后使用sqrt((x1-x1)^ 2 +(y1 y2)^ 2)。得到边的长度。

You clarified your question so if you have a rectangle and you know the angle from the top left corner is rotated away from the top so the left side looks like this.
  /
/
a = sine(alpha)*width
b = cosine(alpha)*width
c = sine(alpha)*height
d = cosine(alpha)*height

你澄清了你的问题,如果你有一个矩形,你知道左上角的角度是从上往下旋转的所以左边是这样的。/ / a = sin()*宽度b = cos()*宽度c = sin()*高d = cos (alpha)*高。

width = a + d
height = b + c
Be sure you get the angle right it is kind of hard to clarify it on here. If you get the other angle then it will come out to
width = b + c
height = a + d

宽度= a + d高度= b + c,确定角度是正确的这在这里很难解释。如果你得到另一个角,它就会出来,宽度= b + c高度= a + d。

#4


0  

For the axis aligned box of the rotated rectangle, you find the minimum and maximum of each of the 4 rotated coordintates. The minX and minY becomes 1 corner and the maxX and maxY becomes the other corner.

对于旋转矩形的轴对齐框,您可以找到四个旋转的coordintates的最小值和最大值。minX和minY变成了一个角,maxX和maxY变成另一个角。

#5


-1  

Calculate the area of the original rectangle. Area doesn't change under rotation.

计算原始矩形的面积。面积不会在旋转的情况下改变。

#6


-1  

Use [Heron's Formula Triangle Area Calculator] s = (a + b + c) / 2 or 1/2 of the perimeter of the triangle

使用[Heron的公式三角形区域计算器]s = (a + b + c) /2或三角形周长的1/2。

A = SquareRoot(s * (s - a) * (s - b) * (s - c))

Where

在哪里

a=SquareRoot((X1-X2)^2+(Y1-Y2)^2)  [Side 1 Length]
b=SquareRoot((X1-X3)^2+(Y1-Y3)^2)  [Side 2 Length]
c=SquareRoot((X2-X3)^2+(Y2-Y3)^2)  [Side 3 Length]

X1,Y1,X2,Y2,X3,Y3 are the coordinations of any three points (Corners)

X1,Y1,X2,Y2,X3,Y3是任意三个点的坐标

RectangleArea=2*A

Or Direct without [Heron's Formula Triangle Area Calculator], sequence of points are important here.

或者直接没有[Heron的公式三角区域计算器],点序列在这里很重要。

P1----P2
|     |
P3----P4

 a=SquareRoot((X1-X2)^2+(Y1-Y2)^2)  [Side 1 Length]
 b=SquareRoot((X1-X3)^2+(Y1-Y3)^2)  [Side 2 Length]
 RectangleArea=a*b

#7


-3  

It's a bit complicated, but for a rectangle, Area = b * h = length * width.

这有点复杂,但对于一个矩形,面积= b * h =长*宽。