Class AngleCalc

java.lang.Object
com.graphhopper.util.AngleCalc

public class AngleCalc extends Object
Calculates the angle of a turn, defined by three points. The fast atan2 method is from Jim Shima, 1999, http://www.dspguru.com/dsp/tricks/fixed-point-atan2-with-self-normalization and stands under public domain.
Author:
Johannes Pelzer, Peter Karich
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final AngleCalc
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    alignOrientation(double baseOrientation, double orientation)
    Change the representation of an orientation, so the difference to the given baseOrientation will be smaller or equal to PI (180 degree).
    azimuth2compassPoint(double azimuth)
     
    double
    calcAzimuth(double lat1, double lon1, double lat2, double lon2)
    Calculate the azimuth in degree for a line given by two coordinates.
    double
    calcOrientation(double lat1, double lon1, double lat2, double lon2)
     
    double
    calcOrientation(double lat1, double lon1, double lat2, double lon2, boolean exact)
    Return orientation of line relative to east.
    double
    convertAzimuth2xaxisAngle(double azimuth)
    convert north based clockwise azimuth (0, 360) into x-axis/east based angle (-Pi, Pi)
    boolean
    isClockwise(double aX, double aY, double bX, double bY, double cX, double cY)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ANGLE_CALC

      public static final AngleCalc ANGLE_CALC
  • Constructor Details

    • AngleCalc

      public AngleCalc()
  • Method Details

    • calcOrientation

      public double calcOrientation(double lat1, double lon1, double lat2, double lon2)
    • calcOrientation

      public double calcOrientation(double lat1, double lon1, double lat2, double lon2, boolean exact)
      Return orientation of line relative to east.

      Parameters:
      exact - If false the atan gets calculated faster, but it might contain small errors
      Returns:
      Orientation in interval -pi to +pi where 0 is east
    • convertAzimuth2xaxisAngle

      public double convertAzimuth2xaxisAngle(double azimuth)
      convert north based clockwise azimuth (0, 360) into x-axis/east based angle (-Pi, Pi)
    • alignOrientation

      public double alignOrientation(double baseOrientation, double orientation)
      Change the representation of an orientation, so the difference to the given baseOrientation will be smaller or equal to PI (180 degree). This is achieved by adding or subtracting a 2*PI, so the direction of the orientation will not be changed
    • calcAzimuth

      public double calcAzimuth(double lat1, double lon1, double lat2, double lon2)
      Calculate the azimuth in degree for a line given by two coordinates. Direction in 'degree' where 0 is north, 90 is east, 180 is south and 270 is west.
    • azimuth2compassPoint

      public String azimuth2compassPoint(double azimuth)
    • isClockwise

      public boolean isClockwise(double aX, double aY, double bX, double bY, double cX, double cY)
      Returns:
      true if the given vectors follow a clockwise order abc, bca or cab, false if the order is counter-clockwise cba, acb or bac, e.g. this returns true: a b | / 0 - c