Skip to main content
April 19, 2011
Answered

rotated coordinates

  • April 19, 2011
  • 1 reply
  • 3083 views

when i rotate an image how do i get the new cordinates of the image.
This image is rotated around 0,0 but what is the coordinates of the other corners now it os rotated?

img1.rotation=_angle;

This topic has been closed for replies.
Correct answer Kenneth Kawamoto

The new coordination after the rotation would be:

x' = x*cosθ - y*sinθ

y' = x*sinθ + y*cosθ

So the AS equivalent would be something like:

        private function rotatedPoint(originalPoint:Point, rotation:Number):Point {
            return new Point(originalPoint.x*Math.cos(rotation) - originalPoint.y*Math.sin(rotation), originalPoint.x*Math.sin(rotation) + originalPoint.y*Math.cos(rotation));
        }

So Point(0, 20) after 10 degrees rotation would be:

trace(rotatedPoint(new Point(0, 20), 10*Math.PI/180));

// (x=-3.4729635533386065, y=19.69615506024416)

Sounds about right...?


May be better to round off the number:

        private function rotatedPoint(originalPoint:Point, rotation:Number):Point {
            var p:Point = new Point(originalPoint.x*Math.cos(rotation) - originalPoint.y*Math.sin(rotation), originalPoint.x*Math.sin(rotation) + originalPoint.y*Math.cos(rotation));
            p.x = Math.round(p.x*100)/100;
            p.y = Math.round(p.y*100)/100;
            return p;
        }

1 reply

April 19, 2011

with Math.sin and Math.cos

April 19, 2011

in silverlight when you rotate an object there are properties you can call to get the new rotated coordinates.

In AS3 isnt there a way to get the new corners of the rotated bitmap image?

April 19, 2011

No, there is not as I know.