/// <summary> /// 矩阵转欧拉角 /// </summary> /// <param name="m"></param> /// <param name="angles">3个角度</param> /// <returns></returns> public static FixedVector3 MatrixAngle(this FixedMatrix4x4 m, FixedVector3 angles) { Fixed c; Fixed tx, ty; angles = new FixedVector3(); angles.y = FixedMathf.Asin(m.m02); c = FixedMathf.Cos(angles.y); if (FixedMathf.Abs(c) > 0.005f) { tx = m.m22 / c; ty = -m.m12 / c; angles.x = FixedMathf.Atan2(ty, tx); tx = m.m00 / c; ty = -m.m01 / c; angles.z = FixedMathf.Atan2(ty, tx); } else { angles.x = 0; tx = m.m11; ty = m.m10; angles.z = FixedMathf.Atan2(ty, tx); } return(angles); }
/// <summary> /// 是否在三角形内 /// </summary> /// <param name="point"></param> /// <param name="v0"></param> /// <param name="v1"></param> /// <param name="v2"></param> /// <returns></returns> public static bool isINTriangle(Vector3 point, Vector3 v0, Vector3 v1, Vector3 v2) { float x = point.x; float y = point.z; float v0x = v0.x; float v0y = v0.z; float v1x = v1.x; float v1y = v1.z; float v2x = v2.x; float v2y = v2.z; float t = triangleArea(v0x, v0y, v1x, v1y, v2x, v2y); float a = triangleArea(v0x, v0y, v1x, v1y, x, y) + triangleArea(v0x, v0y, x, y, v2x, v2y) + triangleArea(x, y, v1x, v1y, v2x, v2y); if (FixedMathf.Abs(t - a) <= 0.01f) { return(true); } else { return(false); } }
public static Fixed Angle(FixedQuaternion a, FixedQuaternion b) { Fixed f = Dot(a, b); return(FixedMathf.Acos(FixedMathf.Min(FixedMathf.Abs(f), Fixed.One).AsFloat()) * new Fixed(2) * Fixed.Rad2Deg); }