PDA

Click to See Complete Forum and Search --> : rotated rectangle



grobeat
06-08-2002, 12:19 PM
I got to recreate some rotated rectangles:
What I got, is the Data for rotation, width and height of each one. What I need are the x/y-coordinates like the following (x1,y2,x3,y4):

http://board.flashkit.com/board/
any idea?
greetz
Daniel

Ed Mack
06-08-2002, 04:41 PM
Invent coords for the rectangles edges whilst not rotated, and then to rotate them, do somthing like the following (I think):

angle = 45; // The angle we will rotate by
p1 = {x:5,y:6}; // Point 1's x & y
p2 = {x:45,y:3}; // The same
// ect... for other points

p1.x = Math.cos(angle)*p1.x+Math.sin(angle)*p1.y;
p1.y = Math.cos(angle)*p1.y-Math.sin(angle)*p1.x;

p2.x = Math.cos(angle)*p2.x+Math.sin(angle)*p2.y;
p2.y = Math.cos(angle)*p2.y-Math.sin(angle)*p2.x;

//And so on........ for other points

Please note, this rotates the points around the origin, (0,0)

grobeat
06-09-2002, 07:07 AM
Sorry, I tried to set
p1 = {x:0,y:height};
p2 = {x:width,y:0};
but it doesnt works for me wether the origin is at 0/0 or in the mid.

Let say, the origin coords of the rectangle (rotated by 33.8)itself are
0, 98.5
18.6, height
width, 28
146.4, 0
so I need to figure out these values after rotation: with the width (165.6),height (127.5) and rotation (33.8) of the whole body

greetz
Daniel

Ed Mack
06-09-2002, 07:38 AM
It would need to be

p1 = {x:0,y:_height};

ect...

grobeat
06-09-2002, 08:33 AM
yeah, but its just a variable. Nevertheless:
"Math.cos(angle)*p1.x+Math.sin(angle)*p1.y"
returns wrong values.
All I got is described in following and if I could get the radius of one triangle, it would be easy to get P1.
I mean the constant is the relation _width/_height. ?

http://board.flashkit.com/board/

greetz
Daniel