Overview
ThePoint class represents a geographic coordinate on Earth using latitude and longitude. It provides distance calculation between two points using the Haversine formula.
Constructor
Parameters
The latitude coordinate in decimal degrees (-90 to 90)
The longitude coordinate in decimal degrees (-180 to 180)
Example
Methods
distance()
Calculates the great-circle distance between two points using the Haversine formula.Parameters
Another Point instance to calculate the distance to
Returns
The distance between the two points in kilometers
Implementation
The distance calculation uses the Haversine formula, which determines the great-circle distance between two points on a sphere given their longitudes and latitudes.The Earth’s radius is approximated as 6371 km in this implementation. This provides sufficient accuracy for most terrestrial applications.
Example
Constants
Earth Radius
The Haversine formula uses the Earth’s mean radius:Use Cases
The Point class is used throughout the route-finding algorithm for:- Representing start and destination coordinates
- Calculating walking distances to nearby bus stops
- Determining if a stop is within walking range (maxWalkKm)
- Measuring the remaining distance to the destination
Related Classes
- Stop Class - Extends Point to represent bus stops
- Route Class - Uses Point for distance calculations