Cocos Creator 计算两点角度、距离

Cocos Creator 计算两点角度、距离

// 距离
getDistance:function(start, end){
        var pos = cc.v2(start.x - end.x, start.y - end.y);
        var dis = Math.sqrt(pos.x*pos.x + pos.y*pos.y);
        return dis;
    },
// 角度
getAngle:function(start, end){
        //计算出朝向
        var dx = end.x - start.x;
        var dy = end.y - start.y;
        var dir = cc.v2(dx,dy);

        //根据朝向计算出夹角弧度
        var angle = dir.signAngle(cc.v2(1,0));

        //将弧度转换为欧拉角
        var degree = angle / Math.PI * 180;

        return -degree
    },

你可能感兴趣的:(Cocos,Creator,typescript,几何学,javascript)