/// <summary> /// Returns the aspect ratio of the triangle defined by 3 given points. /// This is defined as the longest edge / shortest altitude. /// </summary> /// <param name="points"></param> /// <returns></returns> public static double GetTriAspect(Vec3d[] points) { double maxEdge = 0.0; // longest edge double minAlt = Double.PositiveInfinity; // shortest altitude for (int i = 0; i < 3; i++) { Vec3d p0 = points[i]; Vec3d p1 = points[(i + 1) % 3]; Vec3d p2 = points[(i + 2) % 3]; Vec3d v0 = p1 - p0; Vec3d v1 = p2 - p1; maxEdge = Math.Max(maxEdge, v0.SquareLength); minAlt = Math.Min(minAlt, Vec3d.Reject(v1, v0).SquareLength); } return(Math.Sqrt(maxEdge) / Math.Sqrt(minAlt)); }
/// <summary> /// Returns the aspect ratio of the triangle defined by 3 given points. /// This is defined as the longest edge / shortest altitude. /// </summary> /// <param name="points"></param> /// <returns></returns> public static double GetTriAspect(Vec3d p0, Vec3d p1, Vec3d p2) { double maxEdge = 0.0; // longest edge double minAlt = Double.PositiveInfinity; // shortest altitude Vec3d v0 = p1 - p0; Vec3d v1 = p2 - p1; Vec3d v2 = p0 - p2; Sub(v0, v1); Sub(v1, v2); Sub(v2, v0); return(Math.Sqrt(maxEdge) / Math.Sqrt(minAlt)); void Sub(Vec3d a, Vec3d b) { maxEdge = Math.Max(maxEdge, a.SquareLength); minAlt = Math.Min(minAlt, Vec3d.Reject(b, a).SquareLength); } }