com.caffeineowl.graphics
Class GeomUtils

java.lang.Object
  extended by com.caffeineowl.graphics.GeomUtils

public class GeomUtils
extends java.lang.Object

Class to implement various algorithms related with planar (2D) geometry: intersections, areas, etc.

Author:
Adrian Colomitchi

Field Summary
protected static double angleTolerance
          Maximum tolerance to be used when dealing with angles.
protected static double areaTolerance
          Maximum tolerance to be used when dealing with areas.
protected static double distTolerance
          Maximum tolerance to be used when dealing with distances.
 
Constructor Summary
GeomUtils()
           
 
Method Summary
(package private) static boolean arePointsCollinear(double ax, double ay, double bx, double by, double cx, double cy)
          The points will be considered collinear (on the same straight line, including the degenerate cases) iff the area of the triangle defined by the three points is zero.
static double getAngleTolerance()
           
static double getAreaTolerance()
           
static double getDistTolerance()
           
(package private) static boolean lineSeparatesPoints(double startx, double starty, double endx, double endy, double p0x, double p0y, double p1x, double p1y, boolean strict)
          The points p0 and p1 will be considered separated by the line passing through start and end if, while "staying in start and looking towards end, one case see the p0 by turning their head on the opposite side of the line as for seeing p1".
static void setAngleTolerance(double angleTolerance)
           
static void setAreaTolerance(double areaTolerance)
           
static void setDistTolerance(double distTolerance)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

distTolerance

protected static double distTolerance
Maximum tolerance to be used when dealing with distances. Values under this tolerance are considered as 0 (zero); or, locations separated by distances less than this value will be considered as being the same/indiscernible.


angleTolerance

protected static double angleTolerance
Maximum tolerance to be used when dealing with angles. Values under this tolerance are considered as 0 (zero).


areaTolerance

protected static double areaTolerance
Maximum tolerance to be used when dealing with areas. Values under this tolerance are considered as 0 (zero).

Constructor Detail

GeomUtils

public GeomUtils()
Method Detail

getDistTolerance

public static final double getDistTolerance()
Returns:
the angleTolerance

setDistTolerance

public static final void setDistTolerance(double distTolerance)
Parameters:
distTolerance - the distTolerance to set

getAngleTolerance

public static final double getAngleTolerance()
Returns:
the angleTolerance

setAngleTolerance

public static final void setAngleTolerance(double angleTolerance)
Parameters:
angleTolerance - the angleTolerance to set

getAreaTolerance

public static double getAreaTolerance()
Returns:
the areaTolerance

setAreaTolerance

public static void setAreaTolerance(double areaTolerance)
Parameters:
areaTolerance - the areaTolerance to set

arePointsCollinear

static final boolean arePointsCollinear(double ax,
                                        double ay,
                                        double bx,
                                        double by,
                                        double cx,
                                        double cy)
The points will be considered collinear (on the same straight line, including the degenerate cases) iff the area of the triangle defined by the three points is zero. The method actually compute the double of this area, by using the cross-product of (b-ax (c-a): if this is below the tolerance, the points will be considered collinear.


lineSeparatesPoints

static final boolean lineSeparatesPoints(double startx,
                                         double starty,
                                         double endx,
                                         double endy,
                                         double p0x,
                                         double p0y,
                                         double p1x,
                                         double p1y,
                                         boolean strict)
The points p0 and p1 will be considered separated by the line passing through start and end if, while "staying in start and looking towards end, one case see the p0 by turning their head on the opposite side of the line as for seeing p1". As the "angle of turning" will have the same sign as the cross-product, between the vector defining the two directions, the method simply relies on the fact that the signum of the two cross-products must be opposite.

Note: if the line defined by start and end is a degenerate one (i.e. the start and end points are equal or very close on of the other) the return value will be strongly affected by the computation errors, but mostly the return value will be given by the value of the strict parameter.

Parameters:
strict - if true, having one of the p0 or p1 on the start->end line will cause this method to return false (i.e. the points must be really separated by the line, with none of them on the line). If false, then any (or both) of the points being on the line will cause a positive response.