// ----------- Part 11: useful functions ------------- // Compute the range in meters between this Position and // the Position passed as input. // @param right Position to which to find the range // @return the range (in meters) // @throw GeometryException if ell values differ public static double Range(Position left, Position right) { if (left.Ellipsoid != right.Ellipsoid) { throw new Exception("Unequal geoids"); } left.TransformTo(CoordinateSystem.Cartesian); right.TransformTo(CoordinateSystem.Cartesian); double result = MiscMath.RSS(left.X - right.X, left.X - right.Y, left.Z - right.Z); return(result); }
// Fundamental routine to convert cartesian to spherical coordinates. // @param xyz (input): X,Y,Z // @param trp (output): theta, phi (deg), radius in units of input // Algorithm references: standard geometry. public void ConvertCartesianToSpherical(Triple xyz, out Triple tpr) { tpr = new Triple(); tpr[2] = MiscMath.RSS(xyz[0], xyz[1], xyz[2]); if (tpr[2] <= POSITION_TOLERANCE / 5) { // zero-length Cartesian vector tpr[0] = 90; tpr[1] = 0; return; } tpr[0] = Math.Acos(xyz[2] / tpr[2]); tpr[0] *= C.RAD_TO_DEG; if (MiscMath.RSS(xyz[0], xyz[1]) < POSITION_TOLERANCE / 5) { // pole tpr[1] = 0; return; } tpr[1] = Math.Atan2(xyz[1], xyz[0]); tpr[1] *= C.RAD_TO_DEG; if (tpr[1] < 0) { tpr[1] += 360; } }
public static void Example() { Console.WriteLine(MiscMath.RSS(0, 3, 4)); }