com.caffeineowl.graphics
Class DistUtils

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

public final class DistUtils
extends java.lang.Object

Utility functions to deal with lines, line segments, etc.

Author:
Adrian Colomitchi

Constructor Summary
DistUtils()
           
 
Method Summary
static double pointToLineEucDist(double pointX, double pointY, double startX, double startY, double endX, double endY)
          Computes the euclidian distance between a point and its' projection on a line (distance between a point and the line).
static double pointToLineSqEucDist(double pointX, double pointY, double startX, double startY, double endX, double endY)
          Computes the square of the euclidian distance between a point and its' projection on a line (the distance between a point and the line).
static double pointToPointCbsvDist(double p1x, double p1y, double p2x, double p2y)
          The the chess (Chebyshev) distance between two points.
static double pointToPointEucDist(double p1x, double p1y, double p2x, double p2y)
          The the euclidian distance between two points.
static double pointToPointMnhtDist(double p1x, double p1y, double p2x, double p2y)
          The the Manhattan distance between two points.
static double pointToPointSqEucDist(double p1x, double p1y, double p2x, double p2y)
          The square of the euclidian distance between two points.
static double pointToSegEucDist(double pointX, double pointY, double startX, double startY, double endX, double endY)
          Computes the the minimum euclidian distance to the segment's point which is the closest to the original point.
static double pointToSegSqEucDist(double pointX, double pointY, double startX, double startY, double endX, double endY)
          Computes the the minimum squared euclidian distance to the segment's point which is the closest to the original point.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DistUtils

public DistUtils()
Method Detail

pointToPointSqEucDist

public static final double pointToPointSqEucDist(double p1x,
                                                 double p1y,
                                                 double p2x,
                                                 double p2y)
The square of the euclidian distance between two points.

Parameters:
p1x - x coordinate of the first point
p1y - y coordinate of the first point
p2x - x coordinate of the second point
p2y - y coordinate of the second point

pointToPointEucDist

public static final double pointToPointEucDist(double p1x,
                                               double p1y,
                                               double p2x,
                                               double p2y)
The the euclidian distance between two points. Computes it by calling Math.sqrt(@link #pointToLineSqEucDist(double, double, double, double, double, double)) (i.e. more computational extensive than computing the square of the distance).

Parameters:
p1x - x coordinate of the first point
p1y - y coordinate of the first point
p2x - x coordinate of the second point
p2y - y coordinate of the second point

pointToPointMnhtDist

public static final double pointToPointMnhtDist(double p1x,
                                                double p1y,
                                                double p2x,
                                                double p2y)
The the Manhattan distance between two points.

Parameters:
p1x - x coordinate of the first point
p1y - y coordinate of the first point
p2x - x coordinate of the second point
p2y - y coordinate of the second point

pointToPointCbsvDist

public static final double pointToPointCbsvDist(double p1x,
                                                double p1y,
                                                double p2x,
                                                double p2y)
The the chess (Chebyshev) distance between two points.

Parameters:
p1x - x coordinate of the first point
p1y - y coordinate of the first point
p2x - x coordinate of the second point
p2y - y coordinate of the second point

pointToLineSqEucDist

public static final double pointToLineSqEucDist(double pointX,
                                                double pointY,
                                                double startX,
                                                double startY,
                                                double endX,
                                                double endY)
Computes the square of the euclidian distance between a point and its' projection on a line (the distance between a point and the line). no matter if the projection falls outside the [startX, startY]...[endX, endY] segment.

Parameters:
pointX - the x coordinate of the point
pointY - the y coordinate of the point
startX - the x coordinate of the first point on the line
startY - the y coordinate of the first point on the line
endX - the x coordinate of the second point on the line
endY - the y coordinate of the second point on the line

pointToLineEucDist

public static final double pointToLineEucDist(double pointX,
                                              double pointY,
                                              double startX,
                                              double startY,
                                              double endX,
                                              double endY)
Computes the euclidian distance between a point and its' projection on a line (distance between a point and the line). Calls the Math.sqrt(pointToLineSqEucDist), which makes this method more computational intensive than computing the square of the distance.

Parameters:
pointX - the x coordinate of the point
pointY - the y coordinate of the point
startX - the x coordinate of the first point on the line
startY - the y coordinate of the first point on the line
endX - the x coordinate of the second point on the line
endY - the y coordinate of the second point on the line

pointToSegSqEucDist

public static final double pointToSegSqEucDist(double pointX,
                                               double pointY,
                                               double startX,
                                               double startY,
                                               double endX,
                                               double endY)
Computes the the minimum squared euclidian distance to the segment's point which is the closest to the original point. That is, if the projection of the given point falls on the segment, the squared distance to the projection is returned. Otherwise, the method returns the squared distance to the end of the segment that is closest to the given point.

Parameters:
pointX - the x coordinate of the point
pointY - the y coordinate of the point
startX - the x coordinate of the segment's start
startY - the y coordinate of the segment's start
endX - the x coordinate of the segment's end
endY - the y coordinate of the segment's end
Returns:
the squared euclidian distance from the given point to the closest point on the segment.

pointToSegEucDist

public static final double pointToSegEucDist(double pointX,
                                             double pointY,
                                             double startX,
                                             double startY,
                                             double endX,
                                             double endY)
Computes the the minimum euclidian distance to the segment's point which is the closest to the original point. Returns the square root of the pointToSegSqEucDist(double, double, double, double, double, double).