How to get the size of a rotary rectangle

Possible duplicate:
Calculate the coordinates of a rectangle with a rotary rectangle, the image inside.

I have a rotating rectangle. So, how can I calculate the size of the axis-aligned bounding box for the rotated rectangle in 2D coordinates?

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

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

thanks

+8
geometry
source share
7 answers
a = abs(x * sin(o)) + abs(y * cos(o)) b = abs(x * cos(o)) + abs(y * sin(o)) 
+30
source share

To build a bounding box with an axis, you need to find the extreme points of the rotated window. i.e.,

the rectangle "P" defined by the points P1 = (0,0), P2 = (x, 0), P3 (x, y), P4 (0, y), rotated by "R" degrees; find minX, maxX, minY, maxY, so that the field [(minX, minY), (maxX, maxY)] completely limits the rotated "P".

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

The bounding box values ​​are the minimum / maximum components of the rotating points P1 '... P4'; Thus,

 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 two-dimensional turns, see http://en.wikipedia.org/wiki/Transformation_matrix#Rotation

+5
source share

Well, you did not give details. I assume that you know that the height and width of the rectangle will give you the area regardless of rotation. If you only have x, y data, then you use sqrt((x1-x1)^2 + (y1-y2)^2) . To get the length of the side.

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

width = a + d
height = b + c
Make sure you get the angle to the right, and it's hard to make it clear. If you get another angle then it will come out in width = b + c
height = a + d

+1
source share

For a rectangle aligned with rotation, you will find the minimum and maximum of each of the 4 rotational coordinates. MinX and minY become 1 angular, while maxX and maxY become different.

0
source share

Calculate the area of ​​the original rectangle. The area does not change during rotation.

-one
source share

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

 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 - the coordinates of any three points (Corners)

 RectangleArea=2*A 

Or right without the [Holistic square of a triangle triangle], the sequence of points is important here.

 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 
-one
source share

This is a bit complicated, but for the rectangle Area = b * h = length * width .

-3
source share

All Articles