/// <summary> /// Returns a value suitable for comparing the relative area of two triangles. (E.g. /// Is triangle A larger than triangle B.) /// </summary> /// <remarks> /// <para> /// The value returned by this method can be converted to an area as follows: /// <c>Area = Math.sqrt(value) / 2</c> /// </para> /// <para> /// Useful for cheaply comparing the size of triangles. /// </para> /// </remarks> /// <param name="a">Vertex A of triangle ABC.</param> /// <param name="b">Vertex B of triangle ABC.</param> /// <param name="c">Vertex C of triangle ABC.</param> /// <returns>A value suitable for comparing the relative area of two triangles.</returns> public static float GetAreaComp(Vector3 a, Vector3 b, Vector3 c) { // References: // http://softsurfer.com/Archive/algorithm_0101/algorithm_0101.htm#Modern%20Triangles // Get directional vectors. Vector3 u = b - a; // A -> B Vector3 v = c - a; // A -> C // Cross product. Vector3 n = new Vector3(u.y * v.z - u.z * v.y , -u.x * v.z + u.z * v.x , u.x * v.y - u.y * v.x); return(Vector3Util.GetLengthSq(n)); }