/// <summary> /// Returns the distance that is appropriate for N dimensions. In otherwords, if this point is /// three dimensional, then all three dimensions will be used for calculating the distance. /// </summary> /// <param name="coordinate">The coordinate to compare to this coordinate</param> /// <returns>A double valued distance measure that is invariant to the number of coordinates</returns> /// <exception cref="CoordinateMismatchException">The number of dimensions does not match between the points.</exception> public double HyperDistance(Coordinate coordinate) { if (coordinate.NumOrdinates != NumOrdinates) { throw new CoordinateMismatchException(); } double sqrDist = 0; double[] vals = coordinate.ToArray(); for (int i = 0; i < NumOrdinates; i++) { double diff = vals[i] - Coordinate[i]; sqrDist += diff * diff; } return(Math.Sqrt(sqrDist)); }
/// <summary> /// Returns the distance that is appropriate for N dimensions. In otherwords, if this point is /// three dimensional, then all three dimensions will be used for calculating the distance. /// </summary> /// <param name="coordinate">The coordinate to compare to this coordinate</param> /// <returns>A double valued distance measure that is invariant to the number of coordinates</returns> /// <exception cref="CoordinateMismatchException">The number of dimensions does not match between the points.</exception> public double HyperDistance(Coordinate coordinate) { if (coordinate.NumOrdinates != NumOrdinates) { throw new CoordinateMismatchException(); } double[] vals = coordinate.ToArray(); double diff = vals[0] - Convert.ToDouble(_x); double sqrDist = diff * diff; diff = vals[1] - Convert.ToDouble(_y); sqrDist += diff * diff; diff = vals[2] - Convert.ToDouble(_z); sqrDist += diff * diff; return(Math.Sqrt(sqrDist)); }
/// <summary> /// Creates an array of ordinate values that is the size of NumDimensions. This /// will not include an M value. /// </summary> /// <returns>An Array of double values, with one value for each ordinate.</returns> public double[] ToArray() { return(Coordinate.ToArray()); }