/// <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 a SlowCoordinate from any ICoordinate Interface /// </summary> /// <param name="coordinate">The Vector.IPoint interface to construct a coordinate from</param> public SlowCoordinate(Coordinate coordinate) { _numOrdinates = coordinate.NumOrdinates; _values = new double[_numOrdinates]; double[] inVals = coordinate.ToArray(); for (int I = 0; I < _numOrdinates; I++) { _values[I] = inVals[I]; } }