unity 计算两点的的角度

来源:互联网 发布:php判断是否为素数 编辑:程序博客网 时间:2024/05/22 08:21

unity 计算两点的的角度

  float angle_360(Vector3 from_, Vector3 to_)        {            //两点的x、y值            float x = from_.x - to_.x;            float y = from_.y - to_.y;            //斜边长度            float hypotenuse = Mathf.Sqrt(Mathf.Pow(x,2f)+Mathf.Pow(y,2f));            //求出弧度            float cos = x / hypotenuse;            float radian = Mathf.Acos(cos);            //用弧度算出角度                float angle = 180 / (Mathf.PI / radian);            if (y < 0)            {                angle = -angle;            }            else if ((y == 0) && (x < 0))            {                angle = 180;            }            return angle;        }
0 0
原创粉丝点击