com.partnersoft.geometry
Class GeometryLib

java.lang.Object
  extended by com.partnersoft.geometry.GeometryLib

public class GeometryLib
extends java.lang.Object

Various basic double-based geometry functions.

Author:
Paul Reavis Copyright 2003 Partner Software, Inc.

Field Summary
static double eighteenthpi
           
static double feettometers
           
static double halfpi
           
static double meterstofeet
           
static double pi
           
static double threehalfpi
           
static double twopi
           
 
Constructor Summary
GeometryLib()
           
 
Method Summary
static double angle(double x1, double y1, double x2, double y2)
          Returns the angle of a line.
static double angle(Point p1, Point 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 double calculateAngle(Point junior, Point pops)
          Calculates the angle in radians of the line from pops->junior
static TurnVector calculateVector(Point junior, Point pops, Point gramps)
          Calculates the turn vector (distance + angle) of the line from pops->junior as compared to the line from gramps->pops.
static TurnVector calculateVectorFromNorth(Point junior, Point 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(double x1, double y1, double x2, double y2)
          Returns the distance between two points.
static double distance(Point p1, Point p2)
          Returns the distance between two points.
static double distance2(double x1, double y1, double x2, double y2)
          Returns the square of the distance between two points.
static double feetToMeters(double feet)
           
static double getSlope(double x1, double y1, double x2, double y2)
           
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 double makeDiameterEvenMultiple(double original, double partLength)
          Given a diameter and a part length, returns the diameter closest to the given one such that the new circumference is an even multiple of the part length.
static double metersToFeet(double meters)
           
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 Point 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.
static double solveForX(double x1, double y1, double x2, double y2, double newY)
           
static double solveForY(double x1, double y1, double x2, double y2, double newX)
           
 
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

feettometers

public static final double feettometers
See Also:
Constant Field Values

meterstofeet

public static final double meterstofeet
See Also:
Constant Field Values
Constructor Detail

GeometryLib

public GeometryLib()
Method Detail

solveForX

public static final double solveForX(double x1,
                                     double y1,
                                     double x2,
                                     double y2,
                                     double newY)

solveForY

public static final double solveForY(double x1,
                                     double y1,
                                     double x2,
                                     double y2,
                                     double newX)

getSlope

public static final double getSlope(double x1,
                                    double y1,
                                    double x2,
                                    double y2)

roundAngle

public static double roundAngle(double original)

roundAngle

public static double roundAngle(double original,
                                int divisions)

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.


calculateVectorFromNorth

public static TurnVector calculateVectorFromNorth(Point junior,
                                                  Point 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(Point junior,
                                         Point pops,
                                         Point gramps)
Calculates the turn vector (distance + angle) of the line from pops->junior as compared to the line from gramps->pops.


calculateAngle

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


shootBearingAndRange

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


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(Point p1,
                              Point 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 points.


distance2

public static double distance2(double x1,
                               double y1,
                               double x2,
                               double y2)
Returns the square of the distance between two points.


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(Point p1,
                           Point p2)
Returns the angle of a line.


slope

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


makeDiameterEvenMultiple

public static double makeDiameterEvenMultiple(double original,
                                              double partLength)
Given a diameter and a part length, returns the diameter closest to the given one such that the new circumference is an even multiple of the part length. Used to make circular dashing look pretty.


feetToMeters

public static double feetToMeters(double feet)

metersToFeet

public static double metersToFeet(double meters)