rotated coordinates
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;
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;
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;
}Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.