org.opensha.sha.earthquake.rupForecastImpl.WGCEP_UCERF_2_Final.oldClasses
Class UCERF2_Final_RelativeLocation

java.lang.Object
  extended by org.opensha.sha.earthquake.rupForecastImpl.WGCEP_UCERF_2_Final.oldClasses.UCERF2_Final_RelativeLocation

public final class UCERF2_Final_RelativeLocation
extends Object

This is a reproduction of the RelativeLocation class used during UCERF2 development. Changes to this class over time have slightly changed the UCERF2 results, so this class is now used for consistency. It should only be used by UCERF2, no other classes. Title: RelativeLocation

Description: This class is a distance calculator that deals with Location objects and a Direction object. From either two you can calculate the third. If you pass in 2 Location objects this class will return the Direction between the two. If you pass in a Location and a Direction it can calculate the second Location object. The functions are static therefore this class is never instantiated

These calculations are an adoption from Frankel's FORTRAN code. Perhaps a better code base that is more accurate is the geod.exe program from the USGS. This code incorporates the idea of ellipsiod models into the program. This code is written in c, and can certainly be adopted to java. The geod program is part of the Proj codebase. Here are some reference URLS:

SWR: Note: Depth = - vertical distance

Version:
1.0
Author:
Steven W. Rock

Field Summary
static String C
          Class name used for debbuging
protected static boolean D
          if true print out debugging statements
static double D_COEFF
          Degree to Km conversion at equator
static int R
          Earth radius constant
static double RADIANS_CONVERSION
          Radians to degrees conversion constant
 
Method Summary
static double getApproxHorzDistance(double lat1, double lon1, double lat2, double lon2)
          This computes the approximate horizontal distance (in km) using the standard cartesian coordinate transformation.
static double getApproxHorzDistance(Location loc1, Location loc2)
           
static double getApproxHorzDistToLine(Location loc, Location lineLoc1, Location lineLoc2)
          This computes the closest distance to any point on a line segment defined by two locations.
static double getAzimuth(double lat1, double lon1, double lat2, double lon2)
          Helper method that calculates the angle between two locations (value returned is between -180 and 180 degrees) on the earth.
static double getAzimuth(Location loc1, Location loc2)
          Helper method that calculates the angle between two locations on the earth.
static double getBackAzimuth(double lat1, double lon1, double lat2, double lon2)
          Helper method that calculates the angle between two locations on the earth.
static double getDeltaLatFromKm(double km)
          Converts the latitudes in Kms based on the gridSpacing
static double getDeltaLonFromKm(double lat, double km)
          As the earth is sperical, and does not have a constant radius for each longitude, so we calculate the longitude spacing (in Kms) for ever latitude
static LocationVector getDirection(Location location1, Location location2)
          By passing in two Locations this calculator will determine the Distance object between them.
static double getHorzDistance(double lat1, double lon1, double lat2, double lon2)
          Second way to calculate the distance between two points.
static double getHorzDistance(Location loc1, Location loc2)
           
static Location getLocation(Location location, LocationVector direction)
          Given a Location and a Direction object, this function calculates a second Location the Direction points to (only the azimuth is used; backAzimuth is ignored).
static double getOldFaultLength(FaultTrace trace)
           
static double getTotalDistance(Location loc1, Location loc2)
          This computes the total distance in km.
static double getVertDistance(Location loc1, Location loc2)
           
static double latLonDistance(double lat1, double lon1, double lat2, double lon2)
          THIS ONE SHOULD Great Circle distance Calculator.
static void main(String[] argv)
          Purely a tester function.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

C

public static final String C
Class name used for debbuging

See Also:
Constant Field Values

D

protected static final boolean D
if true print out debugging statements

See Also:
Constant Field Values

R

public static final int R
Earth radius constant

See Also:
Constant Field Values

RADIANS_CONVERSION

public static final double RADIANS_CONVERSION
Radians to degrees conversion constant

See Also:
Constant Field Values

D_COEFF

public static final double D_COEFF
Degree to Km conversion at equator

See Also:
Constant Field Values
Method Detail

getDirection

public static LocationVector getDirection(Location location1,
                                          Location location2)
                                   throws UnsupportedOperationException
By passing in two Locations this calculator will determine the Distance object between them. The four fields calculated are:

Parameters:
location1 - First geographic location
location2 - Second geographic location
Returns:
The direction, decomposition of the vector between two locations
Throws:
UnsupportedOperationException - Thrown if the Locations contain bad data such as invalid latitudes
See Also:
to see the field definitions

getTotalDistance

public static double getTotalDistance(Location loc1,
                                      Location loc2)
This computes the total distance in km.

Parameters:
loc1 -
loc2 -
Returns:

getVertDistance

public static double getVertDistance(Location loc1,
                                     Location loc2)

getLocation

public static Location getLocation(Location location,
                                   LocationVector direction)
                            throws UnsupportedOperationException
Given a Location and a Direction object, this function calculates a second Location the Direction points to (only the azimuth is used; backAzimuth is ignored). The fields calculated for the second Location are:

Parameters:
location1 - First geographic location
direction - Direction object pointing to second Location
Returns:
location2 The second location
Throws:
UnsupportedOperationException - Thrown if the Location or Direction contain bad data such as invalid latitudes
See Also:
to see the field definitions

getApproxHorzDistance

public static double getApproxHorzDistance(double lat1,
                                           double lon1,
                                           double lat2,
                                           double lon2)
This computes the approximate horizontal distance (in km) using the standard cartesian coordinate transformation. Not implemented correctly is lons straddle 360 or 0 degrees!


getHorzDistance

public static double getHorzDistance(double lat1,
                                     double lon1,
                                     double lat2,
                                     double lon2)
Second way to calculate the distance between two points. Obtained off the internet, but forgot where now. When used in comparision with the latLonDistance function you see they give practically the same values at the equator, and only start to diverge near the poles, but still reasonable close to each other. Good for point of comparision.

Note: This function is currently not used, only for testing


getApproxHorzDistance

public static double getApproxHorzDistance(Location loc1,
                                           Location loc2)

getHorzDistance

public static double getHorzDistance(Location loc1,
                                     Location loc2)

getOldFaultLength

public static double getOldFaultLength(FaultTrace trace)

getAzimuth

public static double getAzimuth(double lat1,
                                double lon1,
                                double lat2,
                                double lon2)
Helper method that calculates the angle between two locations (value returned is between -180 and 180 degrees) on the earth.

Parameters:
lat1 - latitude of first point
lon1 - longitude of first point
lat2 - latitude of second point
lon2 - longitude of second point
Returns:
angle between the two lat/lon locations

getAzimuth

public static double getAzimuth(Location loc1,
                                Location loc2)
Helper method that calculates the angle between two locations on the earth.

Parameters:
loc1 - location of first point
loc2 - location of second point
Returns:
angle between the two locations

getBackAzimuth

public static double getBackAzimuth(double lat1,
                                    double lon1,
                                    double lat2,
                                    double lon2)
Helper method that calculates the angle between two locations on the earth.

Note: SWR: I'm not quite sure of the difference between azimuth and back azimuth. Ned, you will have to fill in the details.

Parameters:
lat1 - latitude of first point
lon1 - longitude of first point
lat2 - latitude of second point
lon2 - longitude of second point
Returns:
angle between the two lat/lon locations

getDeltaLatFromKm

public static double getDeltaLatFromKm(double km)
Converts the latitudes in Kms based on the gridSpacing

Returns:

getDeltaLonFromKm

public static double getDeltaLonFromKm(double lat,
                                       double km)
As the earth is sperical, and does not have a constant radius for each longitude, so we calculate the longitude spacing (in Kms) for ever latitude

Parameters:
lat= - value of long for every lat according to gridSpacing
Returns:

main

public static void main(String[] argv)
Purely a tester function. I like to put main() functions for unit testing java files. This is a convinient and quick test of the class, and shows exact examples on how to use this class. Tests various examples of Locations and Directions to calculate the RelativeLocation and direction between points. This is mainly a test function

Parameters:
argv - Passed in command line arguments

latLonDistance

public static double latLonDistance(double lat1,
                                    double lon1,
                                    double lat2,
                                    double lon2)
THIS ONE SHOULD Great Circle distance Calculator. Radius of the Earth in km... change this to express the great cirle in other units. Coordinates must be entered in decimal degrees of longitude and latitude. Longitude for the western hemisphere and latitude for the southern hemisphere are expressed as negative values.

Returns:
Description of the Return Value

getApproxHorzDistToLine

public static double getApproxHorzDistToLine(Location loc,
                                             Location lineLoc1,
                                             Location lineLoc2)
This computes the closest distance to any point on a line segment defined by two locations. This is approximate because all points are converted to a cartesian coordinate system (from which the distance is computed analytically), and this conversion is sensitive to the latatude chosen for the x-axis compression as you go to higher latitudes (this uses the average of the given location latitude and the line-midpoint latitude). This throws a Runtime Exception if any of the longitudes differ by more than 20 degrees (arbitrarily chosen to avoid really bad estimates).

Parameters:
loc -
lineLoc1 - - 1st point defining the line
lineLoc2 - - 2nd point defining the line
Returns: