A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: rotated rectangle

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    10
    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):


    any idea?
    greetz
    Daniel

  2. #2
    Gross Pecululatarian Ed Mack's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    2,954
    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)


  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    10

    my math!

    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


  4. #4
    Gross Pecululatarian Ed Mack's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    2,954
    It would need to be

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

    ect...

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    10

    my math!

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



    greetz
    Daniel


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center