CEarth

$Revision: 6 $

Description

This class encapsulates the Earth. It holds the data necessary to perform the calculations of distance and direction. The Earth is not a perfect sphere. It is an ellipsoid (flattened at the top and bottom). All angles are expressed in degrees and all distances are expressed in meters.

Methods

void AddLineOfSightDistanceAndDirectionToCoordinate( const CPolarCoordinate& point_1, double distance, double direction, CPolarCoordinate& point_2, double height_above_surface_of_point_2 = 0.0 )
If you were to shine a laser from point_1 pointing towards direction for distance meters, this function will tell you what location you would be at. It will also let you specify a point height_above_surface_of_point_2 meters above the surface. This method does not take into account the curvature of the Earth.
void AddSurfaceDistanceAndDirectionToCoordinate( const CEarthCoordinate& point_1, double distance, double direction, CEarthCoordinate& point_2 )
void AddSurfaceDistanceAndDirectionToCoordinate( const CEarthCoordinate& point_1, double distance, double direction, CPolarCoordinate& point_2 )
void AddSurfaceDistanceAndDirectionToCoordinate( const CPolarCoordinate& point_1, double distance, double direction, CEarthCoordinate& point_2 )
void AddSurfaceDistanceAndDirectionToCoordinate( const CPolarCoordinate& point_1, double distance, double direction, CPolarCoordinate& point_2 )
This allows you to add a distance over the surface of the Earth to a location and get a new location. It answers the question "If I head out in this direction for that amout of meters, where will I be?"
void Convert( const CEarthCoordinate& cartesian_coordinate, CPolarCoordinate& polar_coordinate ) const
void Convert( const CPolarCoordinate& polar_coordinate, CEarthCoordinate& cartesian_coordinate ) const
This method allows you to convert from polar and cartestian coordinates.
double GetDistanceToHorizon( const CEarthCoordinate& point_1 ) const
double GetDistanceToHorizon( const CPolarCoordinate& point_1 ) const
This tells you how far (in meters) from the horizon point_1 is.
double GetEquatorialRadiusInMeters( void ) const
This tells you what the equatorial radius is in meters for the selected ellipsoid.
double GetPolarRadiusInMeters( void ) const
This tells you what the polar radius is in meters for the selected ellipsoid.
double GetLineOfSightDistanceFromCourse( const CEarthCoordinate& current_location, const CEarthCoordinate& point_a, const CEarthCoordinate& point_b ) const
Draw a line from point_a to point_b. This function will tell you how far current_location is from that line.
double GetLineOfSightDistance( const CEarthCoordinate& point_1, const CEarthCoordinate& point_2 ) const
double GetLineOfSightDistance( const CPolarCoordinate& point_1, const CEarthCoordinate& point_2 ) const
double GetLineOfSightDistance( const CEarthCoordinate& point_1, const CPolarCoordinate& point_2 ) const
double GetLineOfSightDistance( const CPolarCoordinate& point_1, const CPolarCoordinate& point_2 ) const
This will tell you how many meters it is between two points. It answers the question, "If I pointed a laser from point_1 to point_2, how far would the laser beam travel?"
double GetSurfaceDistance( const CEarthCoordinate& point_1, const CEarthCoordinate& point_2, double * heading_from_point_1_to_point_2 = 0, double * heading_from_point_2_to_point_1 = 0 ) const
double GetSurfaceDistance( const CEarthCoordinate& point_1, const CPolarCoordinate& point_2, double * heading_from_point_1_to_point_2 = 0, double * heading_from_point_2_to_point_1 = 0 ) const
double GetSurfaceDistance( const CPolarCoordinate& point_1, const CEarthCoordinate& point_2, double * heading_from_point_1_to_point_2 = 0, double * heading_from_point_2_to_point_1 = 0 ) const
double GetSurfaceDistance( const CPolarCoordinate& point_1, const CPolarCoordinate& point_2, double * heading_from_point_1_to_point_2 = 0, double * heading_from_point_2_to_point_1 = 0 ) const
This will tell you how many meters it is between two points. It answers the question, "If I were to walk from point_1 to point_2, how far would I walk?"
void SetEllipsoid( int ellipsoid )
This allows you to set the ellipsoid used by CEarth in its calculations. The default is WGS84 which is generally accepted as being the closest approximation of the Earth's ellipsoid. The ellipsoid parameter may be one of the following:
void SetEllipsoidByRadii( double equatorial_radius, double polar_radius )
This let's you use your own (custom) values to describe the ellipsoid of the Earth.
void SetEllipsoidByEquatorialRadiusAndFlattening( double equatorial_radius, double flattening )
This let's you use your own (custom) values to describe the ellipsoid of the Earth.

Example

#include <stdio.h>
#include <GFC.h>
#pragma hdrstop

void main( void )
{
   // Let's figure out how far it is from here to there

   CPolarCoordinate here;
   CPolarCoordinate there;

   // Convert from Latitude/Longitude to coordinates our system understands

   // here is 39 degrees 12.152 minutes North Latitude, 76 degrees 46.795 minutes West Longitude
   here.SetUpDownAngleInDegrees(     CMath::ConvertDegreesMinutesSecondsCoordinateToDecimalDegrees(  39.0, 12.152, 0.0 ) );
   here.SetLeftRightAngleInDegrees(  CMath::ConvertDegreesMinutesSecondsCoordinateToDecimalDegrees( -76.0, 46.795, 0.0 ) );

   // there is 12 degrees 8.535 minutes North Latitude, 68 degrees 16.547 West Longitude
   there.SetUpDownAngleInDegrees(    CMath::ConvertDegreesMinutesSecondsCoordinateToDecimalDegrees(  12.0,  8.535, 0.0 ) );
   there.SetLeftRightAngleInDegrees( CMath::ConvertDegreesMinutesSecondsCoordinateToDecimalDegrees( -68.0, 16.547, 0.0 ) );

   CEarth earth; // We are talking about the earth...

   double distance_in_meters         = 0.0;
   double heading_from_here_to_there = 0.0;
   double heading_from_there_to_here = 0.0;

   distance_in_meters = earth.GetSurfaceDistance( here, there, &heading_from_here_to_there, &heading_from_there_to_here );

   printf( "Distance between here and there: %.23lf meters\nHeading from here to there:      %.19lf degrees\nHeading from there to here:      %.19lf degrees\n",
           distance_in_meters,
           heading_from_here_to_there,
           heading_from_there_to_here );

   double degrees = 0.0;
   double minutes = 0.0;
   double seconds = 0.0;

   CMath::ConvertDecimalDegreesToDegreesMinutesSeconds( heading_from_here_to_there, degrees, minutes, seconds );
   printf( "Heading %lf degrees, %lf minutes, %lf seconds\n", degrees, minutes, seconds );

   CMath::ConvertDecimalDegreesToDegreesMinutesSeconds( heading_from_there_to_here, degrees, minutes, seconds );
   printf( "Heading %lf degrees, %lf minutes, %lf seconds\n", degrees, minutes, seconds );
}
Copyright, 1997, Samuel R. Blackburn
$Workfile: CEarth.cpp $
$Modtime: 5/21/97 6:14a $