A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Find four points of rotated rectangle

Threaded View

  1. #7
    Viral tick lordofduct's Avatar
    Join Date
    May 2008
    Location
    South Florida
    Posts
    159
    Code:
    function getRotatedRectPoint( angle:Number, point:Point, rotationPoint:Point = null):Point
    {
    	var ix:Number = (rotationPoint) ? rotationPoint.x : 0;
    	var iy:Number = (rotationPoint) ? rotationPoint.y : 0;
    	
    	var m:Matrix = new Matrix( 1,0,0,1, point.x - ix, point.y - iy);
    	m.rotate(angle);
    	return new Point( m.tx + ix, m.ty + iy);
    }
    Use matrices, it makes it a lot faster and easier.

    angle is in radians
    point the corner's position you are finding.
    rotationPoint - position in the rectangle when not rotated to be rotating around... if you don't include a rotationPoint and leave it null, it rotates around (0,0), or the upperleft corner.

    so for instance a rectangle rotated around (0,0) with width = 100, and height = 50, and rotated 90 degrees:

    Code:
    var upperRight:Point = getRotatedRectPoint( Math.PI / 2, new Point(100,0));
    var lowerRight:Point = getRoatedRectPoint(Math.PI / 2, new Point(100,50));
    var lowerLeft:Point = getRotatedRectPoint(Math.PI / 2, new Point(0,50));
    Last edited by lordofduct; 08-21-2008 at 07:10 PM.

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