com.partnersoft.v3x.graphics
Class VectorLib

java.lang.Object
  extended by com.partnersoft.v3x.graphics.VectorLib

public class VectorLib
extends java.lang.Object

A library class with handy static methods for manipulating vector coordinates.


Field Summary
static double defaultAccuracy
           
static double eighteenthpi
           
static double halfpi
           
static double pi
           
static double threehalfpi
           
static double twopi
           
 
Constructor Summary
VectorLib()
           
 
Method Summary
static double angle(Coord2D p1, Coord2D p2)
          Returns the angle of a line.
static double angle(double x1, double y1, double x2, double y2)
          Returns the angle of a line.
static double angle(DoublePoint p1, DoublePoint p2)
          Returns the angle of a line.
static double angleBetween(double theta1, double theta2)
          Calculates the shortest difference, in canonical radians, between two angles.
static Coord2D average(Coord2D p1, Coord2D p2)
          Returns the average of two points.
static double calculateAngle(Coord3D junior, Coord3D pops)
          Calculates the angle in radians of the line from pops->junior
static TurnVector calculateVector(Coord3D junior, Coord3D pops, Coord3D gramps)
          Calculates the turn vector (distance + angle) of the line from pops->junior as compared to the line from gramps->pops.
static TurnVector calculateVectorFromNorth(Coord3D junior, Coord3D pops)
          Calculates the turn vector (distance + angle) of the line from pops->junior as compared to the line from due south to pops.
static double canonicalAngle(double original)
          Translates an angle in radians into canonical (0 < theta < 2*pi)
static boolean covers(double x1, double y1, double width1, double height1, double x2, double y2, double width2, double height2)
          Returns true if the first rectangle completely covers the second.
static double deflectionAngle(double original)
          Translates an angle in radians into deflection (-pi < theta < pi)
static double degreesToRadians(double degrees)
          Translates an angle in degrees to an angle in radians.
static double distance(Coord2D p1, Coord2D p2)
          Returns the distance between two points.
static double distance(Coord3D p1, Coord3D p2)
          Returns the distance between two points.
static double distance(double x1, double y1, double x2, double y2)
          Returns the distance between two 2D points.
static double distance(DoublePoint p1, DoublePoint p2)
          Returns the distance between two DoublePoints.
static AngleFormat getDefaultAngleFormat()
           
static Coord3D getSecondPoint(double distance, double angle, Coord3D originalLocation)
          returns a second point (perhaps a better name??)
static boolean inside(double x1, double y1, double width, double height, double x2, double y2)
          Returns true if the coordinate is inside the rectangle.
static boolean overlaps(double x1, double y1, double width1, double height1, double x2, double y2, double width2, double height2)
          Returns true if the given rectangles overlap.
static double radiansToDegrees(double radians)
          Translates an angle in radians into an angle in degrees.
static double roundAngle(double original)
           
static double roundAngle(double original, int divisions)
           
static void setDefaultAngleFormat(AngleFormat newFormat)
           
static DoublePoint shootBearingAndRange(double x, double y, double bearing, double range)
          Calculates a second point using bearing and range.
static double slope(double x1, double x2, double y1, double y2)
          Returns the slope of a line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pi

public static final double pi
See Also:
Constant Field Values

twopi

public static final double twopi
See Also:
Constant Field Values

halfpi

public static final double halfpi
See Also:
Constant Field Values

threehalfpi

public static final double threehalfpi
See Also:
Constant Field Values

eighteenthpi

public static final double eighteenthpi
See Also:
Constant Field Values

defaultAccuracy

public static double defaultAccuracy
Constructor Detail

VectorLib

public VectorLib()
Method Detail

calculateVectorFromNorth

public static TurnVector calculateVectorFromNorth(Coord3D junior,
                                                  Coord3D pops)
Calculates the turn vector (distance + angle) of the line from pops->junior as compared to the line from due south to pops. This means due north is zero, hence the name.


calculateVector

public static TurnVector calculateVector(Coord3D junior,
                                         Coord3D pops,
                                         Coord3D gramps)
Calculates the turn vector (distance + angle) of the line from pops->junior as compared to the line from gramps->pops.


roundAngle

public static double roundAngle(double original)

roundAngle

public static double roundAngle(double original,
                                int divisions)

calculateAngle

public static double calculateAngle(Coord3D junior,
                                    Coord3D pops)
Calculates the angle in radians of the line from pops->junior


canonicalAngle

public static double canonicalAngle(double original)
Translates an angle in radians into canonical (0 < theta < 2*pi)


angleBetween

public static double angleBetween(double theta1,
                                  double theta2)
Calculates the shortest difference, in canonical radians, between two angles.


deflectionAngle

public static double deflectionAngle(double original)
Translates an angle in radians into deflection (-pi < theta < pi)


radiansToDegrees

public static double radiansToDegrees(double radians)
Translates an angle in radians into an angle in degrees.


degreesToRadians

public static double degreesToRadians(double degrees)
Translates an angle in degrees to an angle in radians.


overlaps

public static boolean overlaps(double x1,
                               double y1,
                               double width1,
                               double height1,
                               double x2,
                               double y2,
                               double width2,
                               double height2)
Returns true if the given rectangles overlap.


covers

public static boolean covers(double x1,
                             double y1,
                             double width1,
                             double height1,
                             double x2,
                             double y2,
                             double width2,
                             double height2)
Returns true if the first rectangle completely covers the second.


inside

public static boolean inside(double x1,
                             double y1,
                             double width,
                             double height,
                             double x2,
                             double y2)
Returns true if the coordinate is inside the rectangle. This currently includes the boundaries.


distance

public static double distance(Coord3D p1,
                              Coord3D p2)
Returns the distance between two points.


getSecondPoint

public static Coord3D getSecondPoint(double distance,
                                     double angle,
                                     Coord3D originalLocation)
returns a second point (perhaps a better name??)


shootBearingAndRange

public static DoublePoint shootBearingAndRange(double x,
                                               double y,
                                               double bearing,
                                               double range)
Calculates a second point using bearing and range.


distance

public static double distance(Coord2D p1,
                              Coord2D p2)
Returns the distance between two points.


distance

public static double distance(double x1,
                              double y1,
                              double x2,
                              double y2)
Returns the distance between two 2D points.


distance

public static double distance(DoublePoint p1,
                              DoublePoint p2)
Returns the distance between two DoublePoints.


angle

public static double angle(Coord2D p1,
                           Coord2D p2)
Returns the angle of a line.


angle

public static double angle(double x1,
                           double y1,
                           double x2,
                           double y2)
Returns the angle of a line. Zero is due east (towards positive X axis), angles proceed counter-clockwise.


angle

public static double angle(DoublePoint p1,
                           DoublePoint p2)
Returns the angle of a line.


average

public static Coord2D average(Coord2D p1,
                              Coord2D p2)
Returns the average of two points.


slope

public static double slope(double x1,
                           double x2,
                           double y1,
                           double y2)
Returns the slope of a line.


setDefaultAngleFormat

public static void setDefaultAngleFormat(AngleFormat newFormat)

getDefaultAngleFormat

public static AngleFormat getDefaultAngleFormat()