org.mars_sim.msp.simulation
Class Coordinates

java.lang.Object
  extended by org.mars_sim.msp.simulation.Coordinates
All Implemented Interfaces:
java.io.Serializable

public class Coordinates
extends java.lang.Object
implements java.io.Serializable

Spherical Coordinates. Represents a location on virtual Mars in spherical coordinates. It provides some useful methods involving those coordinates, as well as some static methods for general coordinate calculations.

See Also:
Serialized Form

Constructor Summary
Coordinates(Coordinates originalCoordinates)
          Clone constructor
Coordinates(double phi, double theta)
          Constructs a Coordinates object
Coordinates(java.lang.String latitude, java.lang.String longitude)
          Constructor with a latitude and longitude string.
 
Method Summary
 Coordinates convertRectToSpherical(double x, double y)
          Converts linear rectangular XY position change to spherical coordinates
 Coordinates convertRectToSpherical(double x, double y, double rho)
          Converts linear rectangular XY position change to spherical coordinates with rho value for map.
 void convertRectToSpherical(double x, double y, double rho, Coordinates newCoordinates)
          Converts linear rectangular XY position change to spherical coordinates with rho value for map.
 boolean equals(java.lang.Object otherCoords)
          Returns true if coordinates have equal phi and theta values
static IntPoint findRectPosition(Coordinates newCoords, Coordinates centerCoords, double rho, int half_map, int low_edge)
          Converts spherical coordinates to rectangular coordinates.
 IntPoint findRectPosition(double newPhi, double newTheta, double rho, int half_map, int low_edge)
          Converts spherical coordinates to rectangular coordinates.
 double getAngle(Coordinates otherCoords)
          Returns the arc angle in radians between this location and the given coordinates
 double getCosPhi()
          cosine of phi
 double getCosTheta()
          cosine of theta
 Direction getDirectionToPoint(Coordinates otherCoords)
          Returns angle direction to another location on surface of sphere 0 degrees is north (clockwise)
 double getDistance(Coordinates otherCoords)
          Returns the distance in kilometers between this location and the given coordinates
 java.lang.String getFormattedLatitudeString()
          Gets a common formatted string to represent latitude for this location.
 java.lang.String getFormattedLongitudeString()
          Gets a common formatted string to represent longitude for this location.
 java.lang.String getFormattedString()
          Gets a common formatted string to represent this location.
 Coordinates getNewLocation(Direction direction, double distance)
          Gets a new location with a given direction and distance from the current location.
 double getPhi()
          phi accessor
static double getRandomLatitude()
          Gets a random latitude.
static double getRandomLongitude()
          Gets a random longitude.
 double getSinPhi()
          sine of phi.
 double getSinTheta()
          sine of theta
 double getTheta()
          theta accessor
 int hashCode()
          Gets the hash code for this object.
static double parseLatitude(java.lang.String latitude)
          Parse a latitude string into a phi value.
static double parseLongitude(java.lang.String longitude)
          Parse a longitude string into a theta value.
 void setCoords(Coordinates newCoordinates)
          Set coordinates
 void setPhi(double newPhi)
          phi mutator
 void setTheta(double newTheta)
          theta mutator
 java.lang.String toString()
          Generate a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Coordinates

public Coordinates(double phi,
                   double theta)
Constructs a Coordinates object

Parameters:
phi - the phi angle of the spherical coordinate
theta - the theta angle of the spherical coordinate

Coordinates

public Coordinates(Coordinates originalCoordinates)
Clone constructor

Parameters:
originalCoordinates - the Coordinates object to be cloned

Coordinates

public Coordinates(java.lang.String latitude,
                   java.lang.String longitude)
            throws java.lang.Exception
Constructor with a latitude and longitude string.

Parameters:
latitude - String representing latitude value. ex. "25.344 N" or "25.344? N"
longitude - String representing longitude value. ex. "63.5532 W" or "63.5532? W"
Throws:
java.lang.Exception - if latitude or longitude strings are invalid.
Method Detail

toString

public java.lang.String toString()
Generate a string representation of this object. It will be the same format as the formattedString method.

Overrides:
toString in class java.lang.Object
Returns:
String description of Coordinate.
See Also:
getFormattedString()

getPhi

public double getPhi()
phi accessor

Returns:
the phi angle value of the coordinate

setPhi

public void setPhi(double newPhi)
phi mutator

Parameters:
newPhi - the new phi angle value for the coordinate

getTheta

public double getTheta()
theta accessor

Returns:
the theta angle value of the coordinate

setTheta

public void setTheta(double newTheta)
theta mutator

Parameters:
newTheta - the new theta angle value for the coordinate

getSinPhi

public double getSinPhi()
sine of phi.

Returns:
the sine of the phi angle value of the coordinate

getSinTheta

public double getSinTheta()
sine of theta

Returns:
the sine of the theta angle value of the coordinate

getCosPhi

public double getCosPhi()
cosine of phi

Returns:
the cosine of the phi angle value of the coordinate

getCosTheta

public double getCosTheta()
cosine of theta

Returns:
the cosine of the theta angle value of the coordinate

setCoords

public void setCoords(Coordinates newCoordinates)
Set coordinates

Parameters:
newCoordinates - Coordinates object who's location should be matched by this Coordinates object

equals

public boolean equals(java.lang.Object otherCoords)
Returns true if coordinates have equal phi and theta values

Overrides:
equals in class java.lang.Object
Parameters:
otherCoords - Coordinates object to be matched against
Returns:
true if Coordinates values match, false otherwise

hashCode

public int hashCode()
Gets the hash code for this object.

Overrides:
hashCode in class java.lang.Object
Returns:
hash code.

getAngle

public double getAngle(Coordinates otherCoords)
Returns the arc angle in radians between this location and the given coordinates

Parameters:
otherCoords - remote Coordinates object
Returns:
angle (in radians) to the remote Coordinates object

getDistance

public double getDistance(Coordinates otherCoords)
Returns the distance in kilometers between this location and the given coordinates

Parameters:
otherCoords - remote Coordinates object
Returns:
distance (in km) to the remote Coordinates object

getFormattedString

public java.lang.String getFormattedString()
Gets a common formatted string to represent this location.

Returns:
formatted longitude & latitude string for this Coordinates object
See Also:
getFormattedLongitudeString(), getFormattedLatitudeString()

getFormattedLongitudeString

public java.lang.String getFormattedLongitudeString()
Gets a common formatted string to represent longitude for this location. ex. "35.6? E"

Returns:
formatted longitude string for this Coordinates object

getFormattedLatitudeString

public java.lang.String getFormattedLatitudeString()
Gets a common formatted string to represent latitude for this location. ex. "35.6? S"

Returns:
formatted latitude string for this Coordinates object

findRectPosition

public static IntPoint findRectPosition(Coordinates newCoords,
                                        Coordinates centerCoords,
                                        double rho,
                                        int half_map,
                                        int low_edge)
Converts spherical coordinates to rectangular coordinates. Returns integer x and y display coordinates for spherical location.

Parameters:
newCoords - offsetted location
centerCoords - location of the center of the map
rho - diameter of planet (in km)
half_map - half the map's width (in pixels)
low_edge - lower edge of map (in pixels)
Returns:
pixel offset value for map

findRectPosition

public IntPoint findRectPosition(double newPhi,
                                 double newTheta,
                                 double rho,
                                 int half_map,
                                 int low_edge)
Converts spherical coordinates to rectangular coordinates. Returns integer x and y display coordinates for spherical location.

Parameters:
newPhi - the new phi coordinate
newTheta - the new theta coordinate
rho - diameter of planet (in km)
half_map - half the map's width (in pixels)
low_edge - lower edge of map (in pixels)
Returns:
pixel offset value for map

convertRectToSpherical

public Coordinates convertRectToSpherical(double x,
                                          double y)
Converts linear rectangular XY position change to spherical coordinates

Parameters:
x - change in x value (in km)
y - change in y value (in km)
Returns:
new spherical location

convertRectToSpherical

public Coordinates convertRectToSpherical(double x,
                                          double y,
                                          double rho)
Converts linear rectangular XY position change to spherical coordinates with rho value for map.

Parameters:
x - change in x value (in km)
y - change in y value (in km)
rho - rho value of map used
Returns:
new spherical location

convertRectToSpherical

public void convertRectToSpherical(double x,
                                   double y,
                                   double rho,
                                   Coordinates newCoordinates)
Converts linear rectangular XY position change to spherical coordinates with rho value for map.

Parameters:
x - change in x value (in km)
y - change in y value (in km)
rho - rho value of map used
newCoordinates - Coordinates object to put the result in

getDirectionToPoint

public Direction getDirectionToPoint(Coordinates otherCoords)
Returns angle direction to another location on surface of sphere 0 degrees is north (clockwise)

Parameters:
otherCoords - target location
Returns:
angle direction to target (in radians)

getNewLocation

public Coordinates getNewLocation(Direction direction,
                                  double distance)
Gets a new location with a given direction and distance from the current location.

Parameters:
direction - direction to new location
distance - distance to new location (in km)
Returns:
new location coordinates

parseLatitude

public static double parseLatitude(java.lang.String latitude)
                            throws java.text.ParseException
Parse a latitude string into a phi value. ex. "25.344 N" or "25.344? N"

Parameters:
latitude - as string
Returns:
phi value
Throws:
java.text.ParseException - if latitude string could not be parsed.

parseLongitude

public static double parseLongitude(java.lang.String longitude)
                             throws java.text.ParseException
Parse a longitude string into a theta value. ex. "63.5532 W" or "63.5532? W"

Parameters:
longitude - as string
Returns:
theta value
Throws:
java.text.ParseException - if longitude string could not be parsed.

getRandomLatitude

public static double getRandomLatitude()
Gets a random latitude.

Returns:
latitude

getRandomLongitude

public static double getRandomLongitude()
Gets a random longitude.

Returns:
longitude