Unity 已知三点 求 三点之间夹角角度

  public double Angle(Vector3 cen, Vector3 first, Vector3 second)
    {
        double M_PI = 3.1415926535897;

        double ma_x = first.x - cen.x;
        double ma_y = first.y - cen.y;
        double ma_z = first.z - cen.z;
        double mb_x = second.x - cen.x;
        double mb_y = second.y - cen.y;
        double mb_z = second.z - cen.z;
        double v1 = (ma_x * mb_x) + (ma_y * mb_y) + (ma_z * mb_z);
        double ma_val = Math.Sqrt(ma_x * ma_x + ma_y * ma_y + ma_z * ma_z);
        double mb_val = Math.Sqrt(mb_x * mb_x + mb_y * mb_y + mb_z * mb_z);
        double cosM = v1 / (ma_val * mb_val);
        double angleAMB = Math.Acos(cosM) * 180 / M_PI;

        return angleAMB;
    }

你可能感兴趣的:(Unity)