com.graphbuilder.geom
Class Geom

java.lang.Object
  extended bycom.graphbuilder.geom.Geom

public final class Geom
extends java.lang.Object

Geom contains static methods for calculating intersections, angles, areas and distances.


Field Summary
static java.lang.Object INTERSECT
           
static java.lang.Object PARALLEL
           
 
Method Summary
static double getAngle(double originX, double originY, double x, double y)
          The getAngle method returns the angle between (x, y) and (originX, originY).
static double getAngle(Point2d origin, Point2d p)
          Returns the angle between the origin and the specified point.
static boolean getCircle(double x1, double y1, double x2, double y2, double x3, double y3, double[] result)
          Computes the circle formed by three points (x1, y1), (x2, y2) and (x3, y3).
static java.lang.Object getLineLineIntersection(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double[] result)
          Calculates the intersection location of the two lines formed by (x1, y1), (x2, y2) and (x3, y3), (x4, y4).
static java.lang.Object getLineSegIntersection(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double[] result)
          Calculates the intersection location of the line formed by (x1, y1), (x2, y2) and the line segment formed by (x3, y3), (x4, y4).
static java.lang.Object getSegSegIntersection(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double[] result)
          Calculates the intersection location of the line segments formed by (x1, y1), (x2, y2) and (x3, y3), (x4, y4).
static double getTriangleAreaSq(double a, double b, double c)
          Returns the area^2 of the triangle formed by the 3 side-lengths 'a', 'b' and 'c'.
static double getTriangleAreaSq(double x1, double y1, double x2, double y2, double x3, double y3)
          Returns the area^2 of the triangle formed by three points (x1, y1), (x2, y2) and (x3, y3).
static double ptLineDistSq(double[] a, double[] b, double[] c, double[] d, int n)
          Computes the distance between a line (a, b) and a point (c) in n-dimensions.
static double ptLineDistSq(double x1, double y1, double x2, double y2, double x, double y, double[] result)
          The ptLineDistSq method returns the distance between the line formed by (x1, y1), (x2, y2) and the point (x, y).
static double ptSegDistSq(double[] a, double[] b, double[] c, double[] d, int n)
          Computes the distance between a line segment (a, b) and a point (c) in n-dimensions.
static double ptSegDistSq(double x1, double y1, double x2, double y2, double x, double y, double[] result)
          The ptSegDistSq method returns the distance between the line segment formed by (x1, y1), (x2, y2) and the point (x, y).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PARALLEL

public static final java.lang.Object PARALLEL

INTERSECT

public static final java.lang.Object INTERSECT
Method Detail

getAngle

public static double getAngle(double originX,
                              double originY,
                              double x,
                              double y)
The getAngle method returns the angle between (x, y) and (originX, originY). The value returned will be in the range [0.0 : 2 * Math.PI). If the point x, y overlaps the origin then 0.0 is returned. If the point has a positive x and zero y then the value returned is 0.0. If the point has a negative x and zero y then the value returned is Math.PI. If the point has a zero x and positive y then the value returned is Math.PI / 2. If the point has a zero x and negative y then the value returned is 3 * Math.PI / 2.


getAngle

public static double getAngle(Point2d origin,
                              Point2d p)
Returns the angle between the origin and the specified point.

See Also:
getAngle(double,double,double,double)

ptLineDistSq

public static double ptLineDistSq(double x1,
                                  double y1,
                                  double x2,
                                  double y2,
                                  double x,
                                  double y,
                                  double[] result)
The ptLineDistSq method returns the distance between the line formed by (x1, y1), (x2, y2) and the point (x, y). An array of length >= 3 can be passed in to obtain additional information. If the array is not null, then the closest point on the line to the given point is stored in index locations 0 and 1. The parametric value is stored in index location 2.


ptSegDistSq

public static double ptSegDistSq(double x1,
                                 double y1,
                                 double x2,
                                 double y2,
                                 double x,
                                 double y,
                                 double[] result)
The ptSegDistSq method returns the distance between the line segment formed by (x1, y1), (x2, y2) and the point (x, y). An array of length >= 3 can be passed in to obtain additional information. If the array is not null, then the closest point on the line segment to the given point is stored in index locations 0 and 1. The parametric value is stored in index location 2 and its value is >= 0 && <= 1.


ptLineDistSq

public static double ptLineDistSq(double[] a,
                                  double[] b,
                                  double[] c,
                                  double[] d,
                                  int n)
Computes the distance between a line (a, b) and a point (c) in n-dimensions. Arrays a, b, and c must have length greater or equal to n. Array d must have length greater than n. The location of the closest point on the line is stored in d. The parametric value is stored at index location n in d.


ptSegDistSq

public static double ptSegDistSq(double[] a,
                                 double[] b,
                                 double[] c,
                                 double[] d,
                                 int n)
Computes the distance between a line segment (a, b) and a point (c) in n-dimensions. Arrays a, b, and c must have length greater or equal to n. Array d must have length greater than n. The location of the closest point on the line is stored in d. The parametric value is stored at index location n in d, and its value is in the range [0, 1].


getLineLineIntersection

public static java.lang.Object getLineLineIntersection(double x1,
                                                       double y1,
                                                       double x2,
                                                       double y2,
                                                       double x3,
                                                       double y3,
                                                       double x4,
                                                       double y4,
                                                       double[] result)
Calculates the intersection location of the two lines formed by (x1, y1), (x2, y2) and (x3, y3), (x4, y4). If the lines are determined to be parallel, then Geom.PARALLEL is returned and no further computations are done. If the lines are not parallel, then the intersection location is stored in index locations 0 and 1 of the specified array. The parametric value is stored in index location 2. If there is an intersection then the returned value is Geom.INTERSECT.


getLineSegIntersection

public static java.lang.Object getLineSegIntersection(double x1,
                                                      double y1,
                                                      double x2,
                                                      double y2,
                                                      double x3,
                                                      double y3,
                                                      double x4,
                                                      double y4,
                                                      double[] result)
Calculates the intersection location of the line formed by (x1, y1), (x2, y2) and the line segment formed by (x3, y3), (x4, y4). If the line and line segment are determined to be parallel, then Geom.PARALLEL is returned and no further computations are done. If the line segment does not cross the line, then null is returned and no further computations are done. Otherwise the intersection location is stored in index locations 0 and 1 of the specified array. The parametric value with respect to the line segment is stored in index location 2. If there in an intersection then the returned value is Geom.INTERSECT.


getSegSegIntersection

public static java.lang.Object getSegSegIntersection(double x1,
                                                     double y1,
                                                     double x2,
                                                     double y2,
                                                     double x3,
                                                     double y3,
                                                     double x4,
                                                     double y4,
                                                     double[] result)
Calculates the intersection location of the line segments formed by (x1, y1), (x2, y2) and (x3, y3), (x4, y4). If the line segments are determined to be parallel, then Geom.PARALLEL is returned and no further computations are done. If the segments do not cross each other then null is returned and no further computations are done. Otherwise the intersection location is stored in index locations 0 and 1 of the specified array. The parametric value with respect to the first line segment is stored in index location 2. If there is an intersection, then the returned value is Geom.INTERSECT.


getCircle

public static boolean getCircle(double x1,
                                double y1,
                                double x2,
                                double y2,
                                double x3,
                                double y3,
                                double[] result)
Computes the circle formed by three points (x1, y1), (x2, y2) and (x3, y3). If the points are collinear, then false is returned and no further computations are done. If the points are not collinear, then the specified array is used to store the result. The center of the circle is stored in index locations 0 and 1, and the radius squared is stored in index location 2. True is returned if the points are not collinear.


getTriangleAreaSq

public static double getTriangleAreaSq(double x1,
                                       double y1,
                                       double x2,
                                       double y2,
                                       double x3,
                                       double y3)
Returns the area^2 of the triangle formed by three points (x1, y1), (x2, y2) and (x3, y3).


getTriangleAreaSq

public static double getTriangleAreaSq(double a,
                                       double b,
                                       double c)
Returns the area^2 of the triangle formed by the 3 side-lengths 'a', 'b' and 'c'.

Throws:
java.lang.IllegalArgumentException - if the side-lengths are less than 0 or cannot form a triangle.