views:

151

answers:

9

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

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

Thank you

A: 

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

JSBangs
A: 

The same way you calculate the area of a regular one. Length times height.

If you have

A-----B
|     |
D-----C

You take A.distTo(B) * A.distTo(D)

The rotation doesn't change the area.

glowcoder
Northern
@Northern, you should edit your original question, then, to clarify what you meant.
JSBangs
A: 

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

tpdi
A: 

Use [Heron's 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 are the coordinations of any three points (Corners)

RectangleArea=2*A

Or Direct without [Heron's Formula Triangle Area Calculator], sequence of points are 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
Waleed A.K.
+1  A: 

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.

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

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

qw3n
i want to u this fomula too thanks
Northern
@Northern - According to your attached image, you wouldn't use this formula. You would use Area = x * y.
mbeckish
mbeckish is right if you want a and b you need my second forumla not the first.
qw3n
A: 

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.

Michael Dorgan
+1  A: 
a = x * sin(o) + y * cos(o)
b = x * cos(o) + y * sin(o)
Scott Evernden
A: 

Glad to see the question updated. If it is indeed the bounding box you're after, then instead of copying the answer, I'll redirect you here: http://stackoverflow.com/questions/622140/calculate-bounding-box-coordinates-from-a-rotated-rectangle-picture-inside

integer
A: 

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'.

                          +-------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,

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://www.wikimedia.org/wikipedia/en/wiki/Transformation_matrix

eric