/* * 求两点夹角 */ public static float GetAngleTwoPoint(float px1, float py1, float px2, float py2) { float x1 = px2 - px1; float y1 = py2 - py1; float hypotenuse = Mathf.Sqrt(Mathf.Pow(x1, 2) + Mathf.Pow(y1, 2)); float cos = x1 / hypotenuse; float radian = Mathf.Acos(cos); float angle = 180.0f / (Mathf.PI / radian); if (y1 < 0) { angle = -angle; } else if ((y1 == 0) && (x1 < 0)) { angle = 180.0f; } return angle; }
时间: 2024-10-10 03:36:20