A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: 2D rotation problem

  1. #1
    Member
    Join Date
    Jan 2003
    Location
    NY
    Posts
    35

    2D rotation problem

    Hi, I'm starting to experiment with the drawing API and I can't figure this thing out... I'm trying to rotate 2D points about the origin... but when it rotates... it also sizes it down... something must be wrong with my math... can you tell?

    function rotatePoly(){
     var theta = ((Math.PI*degree.text)/180.0);
     for(var i=0;i<thisPolygon.length;i++){
      thisPolygon[i].x = Math.cos(theta)*thisPolygon[i].x-Math.sin(theta)*thisPolygon[i].y;
      thisPolygon[i].y = Math.sin(theta)*thisPolygon[i].x+Math.cos(theta)*thisPolygon[i].y;
     }
     drawPoly();
    }

  2. #2
    Senior Member Penleeki's Avatar
    Join Date
    Mar 2003
    Location
    England
    Posts
    223
    Err, I'm not sure if this is whats causing the problem, but have you noticed that you are rotating the x co-ordinate, and then using the rotated x to calculate the y. This is likely to cause some strange problems.
    I usually use different variables for rotated and original co-ordinates anyway, as they can deform slightly over time if you rotate them a lot.

  3. #3
    Member
    Join Date
    Jan 2003
    Location
    NY
    Posts
    35
    AHA!

    now why didnt i notice that? thanks for pointing that out...that was exactly the problem...

  4. #4
    Senior Member Penleeki's Avatar
    Join Date
    Mar 2003
    Location
    England
    Posts
    223
    No problem.
    It took me ages to figure out what was wrong the first time I did that too.

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