旋转变换javascript 实现

本博客已迁移至 www.0x520.com

旋转变换:http://baike.baidu.com/link?url=h65J3xSG50kV0gF74POk-hsKGYfuCHGxNd4SmIJ5LNZhSBxs6yY-N3SpnvFFQAfpBJhwPF7ygVlkBS4Ntop6vq

    // 旋转公式:
    // Cx,Cy为原点
    // Xo,Yo为初始点
    // θ为旋转角
    // x,y为旋转后的点
    // P'x=Cx+(Xo-Cx)×cosθ-(Yo-Cy)×sinθ
    // P'y=Cy+(Yo-Cy)×cosθ+(Xo-Cx)×sinθ
    JMath.prototype.rotate = function(points,originX,originY,angle)
    {
            //原点
            var Cx = originX; 
            var Cy = originY;
            //旋转角
            var angle = angle;
            //计算
            var _sinAngle = Math.sin(angle * Math.PI / 180).toFixed(15);
            var _cosAngle = Math.cos(angle * Math.PI / 180).toFixed(15);
            var newPoints = [];
            for (var i = 0; i < points.length; i++) {
                    var Xo = points[i][0];
                    var Yo = points[i][1];
                    var x = Cx + (Xo-Cx) * _cosAngle - (Yo-Cy) * _sinAngle;
                    var y = Cy + (Yo-Cy) * _cosAngle + (Xo-Cx) * _sinAngle;
                    newPoints[i] = [x,y];
            }
            return newPoints;
    }

你可能感兴趣的:(旋转变换javascript 实现)