Skip to content

Latest commit

 

History

History
42 lines (31 loc) · 1.17 KB

04.md

File metadata and controls

42 lines (31 loc) · 1.17 KB

4. Matrix

介绍

旋转

缩放

位移

实例

public function getOffsetRange(w:Number, h:Number, rotation:Number):Point
{
    var offsetX:Number = 0;
    var offsetY:Number = 0;

    if (rotation < 0) rotation = rotation % 360 + 360;
    if (rotation > 360) rotation = rotation % 360;

    var radian:Number = rotation * Math.PI / 180; // 弧度

    if (rotation >= 0 && rotation <= 90) {
        offsetX = Math.sin(radian) * h;
    } else if (rotation > 90 && rotation <= 180) {
        offsetX = Math.abs(Math.sin(radian)) * h + Math.abs(Math.cos(radian)) * w;
        offsetY = Math.cos(radian) * h;
    } else if (rotation > 180 && rotation <= 270) {
        offsetX = Math.cos(radian) * w;
        var c:Number = w / Math.abs(Math.tan(radian));
        offsetY = w / Math.abs(Math.sin(radian)) + (h-c) * Math.abs(Math.cos(radian));
    } else if (rotation > 270 && rotation <= 360) {
        offsetY = Math.sin(radian) * w;
    }

    return new Point(Math.abs(offsetX), Math.abs(offsetY));
}

导航