/// <summary> /// Calculates normal. /// </summary> /// <returns>The normal.</returns> /// <param name="a">The alpha component.</param> /// <param name="b">The blue component.</param> /// <param name="c">C.</param> public static Vector3d CalculateTriangleNormal( Vector3d a, Vector3d b, Vector3d c) { Vector3d v1 = b - a; Vector3d v2 = c - a; double x = (v1.y * v2.z) - (v1.z * v2.y); double y = -((v2.z * v1.x) - (v2.x * v1.z)); double z = (v1.x * v2.y) - (v1.y * v2.x); return(Vector3d.Normalize(new Vector3d(x, y, z))); }
/// <summary> /// Normalizes the matrix rows. /// </summary> /// <returns>The rows.</returns> /// <param name="a">The alpha component.</param> public static Matrix3x3 NormalizeRows(Matrix3x3 a) { var r1 = new Vector3d(a.r1c1, a.r1c2, a.r1c3); var r2 = new Vector3d(a.r2c1, a.r2c2, a.r2c3); var r3 = new Vector3d(a.r3c1, a.r3c2, a.r3c3); r1 = Vector3d.Normalize(r1); r2 = Vector3d.Normalize(r2); r3 = Vector3d.Normalize(r3); return(new Matrix3x3( r1.x, r1.y, r1.z, r2.x, r2.y, r2.z, r3.x, r3.y, r3.z)); }
public static Matrix3x3 GetRotationMatrix(Vector3d a, Vector3d b) { a = a.Normalize(); b = b.Normalize(); if (a != b && a.Length() > 0 && b.Length() > 0) { Vector3d c = a.Cross(b); return(new Matrix3x3( a.x, b.x, c.x, a.y, b.y, c.y, a.z, b.z, c.z)); } return(new Matrix3x3()); }
/// <summary> /// Projects the vector on plane. /// </summary> /// <returns>The vector on plane.</returns> /// <param name="normal">Normal.</param> public static Vector3d ProjectVectorOnPlane(Vector3d normal) { if (Math.Abs(normal.x) < 0.000000001) { return(new Vector3d(1.0, 0.0, 0.0)); } if (Math.Abs(normal.y) < 0.000000001) { return(new Vector3d(0.0, 1.0, 0.0)); } if (Math.Abs(normal.z) < 0.000000001) { return(new Vector3d(0.0, 0.0, 1.0)); } double z = -(normal.x + normal.y) / normal.z; return(Vector3d.Normalize(new Vector3d(1.0, 1.0, z))); }