/// <summary>Creates a unit vector perpendicular to the plane described by three spatial coordinates, suitable for being a surface normal.</summary> /// <param name="a">The first spatial coordinate.</param> /// <param name="b">The second spatial coordinate.</param> /// <param name="c">The third spatial coordinate.</param> /// <param name="normal">On success, receives the vector perpendicular to the described plane. On failure, receives Vector3f.Up.</param> /// <returns>The success of the operation. This operation fails if the specified three vectors are colinear.</returns> public static bool CreateNormal(Vector3f a, Vector3f b, Vector3f c, out Vector3f normal) { normal = Vector3f.Cross(b - a, c - a); double norm = normal.X * normal.X + normal.Y * normal.Y + normal.Z * normal.Z; if (norm != 0.0) { normal *= 1.0 / System.Math.Sqrt(norm); return(true); } else { normal = Vector3f.Up; return(false); } }
/// <summary>Checks whether three spatial coordinates are colinear.</summary> /// <param name="a">The first spatial coordinate.</param> /// <param name="b">The second spatial coordinate.</param> /// <param name="c">The third spatial coordinate.</param> /// <returns>A boolean indicating whether the three spatial coordinates are colinear.</returns> public static bool AreColinear(Vector3f a, Vector3f b, Vector3f c) { Vector3f normal = Vector3f.Cross(b - a, c - a); return(IsNullVector(normal)); }