public static bool Perpendicular(VectorF64 a, VectorF64 b) { // Smallest normalized float : 1.1754943e-38 // Smallest normalized double: 2.2250738585072020e-308 double nonZeroThreshold = 1.0e-38; // conservative for double // double: (52+1)-bit mantissa; log10(2^53)=15.95 decimal digits double fractionalDifferenceThreshold = 1.0e-14; // conservative if ((null == a) || (null == b)) { return (false); // Vector is not specified. } if ((null == a.components) || (null == b.components)) { return (false); // Vector is empty. } if (a.Dimensions() != b.Dimensions()) { return (false); // Vectors not the same size. } double lengthA = a.Length(); if (lengthA <= nonZeroThreshold) { return (false); } double lengthB = b.Length(); if (lengthB <= nonZeroThreshold) { return (false); } double zeroImpliesPerpendicular = Math.Abs(VectorF64.Dot(a, b)) / (lengthA * lengthB); double absoluteDifferenceFromZero = Math.Abs(zeroImpliesPerpendicular); if (absoluteDifferenceFromZero <= fractionalDifferenceThreshold) { return (true); } return (false); }
public static double Length(VectorF64 a) { if (null == a) { return (0.0); // Vector not specified. } if (null == a.components) { return (0.0); // Vector is empty. } return (a.Length()); }