|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.neu.ccs.util.Metric
The abstract class Metric define the requirement
for a 2-dimensional distance measure or metric and includes
methods to test when a pair of points are near to one another.
The class contains several static instances of itself, namely, EUCLID, MAX, and SUM. The following relationships hold:
MAX <= EUCLID <= SUM <= 2 * MAX
| Field Summary | |
static Metric |
EUCLID
The EUCLID metric computes the distance between (x1, y1) and (x2,y2) using the classic euclidean metric. |
static Metric |
MAX
The MAX metric computes the distance between (x1, y1) and (x2,y2) using the maximum of the absolute values of the differences in the coordinates. |
static Metric |
SUM
The SUM metric computes the distance between (x1, y1) and (x2,y2) using the sum of the absolute values of the differences in the coordinates. |
| Constructor Summary | |
Metric()
|
|
| Method Summary | |
double |
distance(double[] p1,
double[] p2)
Returns the distance between points p1 and p2. |
abstract double |
distance(double x1,
double y1,
double x2,
double y2)
Returns this distance between (x1,y1) and (x2,y2) in this metric. |
double |
distance(float[] p1,
float[] p2)
Returns the distance between points p1 and p2. |
double |
distance(Point2D p1,
Point2D p2)
Returns the distance between points p1 and p2. |
boolean |
isNear(double[] p1,
double[] p2,
double epsilon)
Returns true if points p1 and p2 have distance less than or equal to epsilon. |
boolean |
isNear(double x1,
double y1,
double x2,
double y2,
double epsilon)
Returns true if (x1,y1) and (x2,y2) have distance less than or equal to epsilon. |
boolean |
isNear(float[] p1,
float[] p2,
double epsilon)
Returns true if points p1 and p2 have distance less than or equal to epsilon. |
boolean |
isNear(Point2D p1,
Point2D p2,
double epsilon)
Returns true if points p1 and p2 have distance less than or equal to epsilon. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final Metric EUCLID
The EUCLID metric computes the distance between (x1, y1) and (x2,y2) using the classic euclidean metric.
Specifically, returns:
Math.sqrt((x * x) + (y * y))
where:
x = x2 - x1
y = y2 - y1
To reduce the chance of overflow, the computation is actually done in a more mathematically stable fashion but the answer is in effect the same as the above formula.
public static final Metric MAX
The MAX metric computes the distance between (x1, y1) and (x2,y2) using the maximum of the absolute values of the differences in the coordinates.
public static final Metric SUM
The SUM metric computes the distance between (x1, y1) and (x2,y2) using the sum of the absolute values of the differences in the coordinates.
| Constructor Detail |
public Metric()
| Method Detail |
public abstract double distance(double x1,
double y1,
double x2,
double y2)
Returns this distance between (x1,y1) and (x2,y2) in this metric.
This is the single abstract method that needs to be instantiated.
x1 - the x-coordinate of point 1y1 - the y-coordinate of point 1x2 - the x-coordinate of point 2y2 - the y-coordinate of point 2
public final double distance(Point2D p1,
Point2D p2)
Returns the distance between points p1 and p2.
Returns Double.MAX_VALUE if either parameter
is null.
p1 - point 1p2 - point 2
public final double distance(double[] p1,
double[] p2)
Returns the distance between points p1 and p2.
Returns Double.MAX_VALUE if either parameter
is null or not of length 2.
p1 - point 1p2 - point 2
public final double distance(float[] p1,
float[] p2)
Returns the distance between points p1 and p2.
Returns Double.MAX_VALUE if either parameter
is null or not of length 2.
p1 - point 1p2 - point 2
public final boolean isNear(double x1,
double y1,
double x2,
double y2,
double epsilon)
Returns true if (x1,y1) and (x2,y2) have distance less than or equal to epsilon.
x1 - the x-coordinate of point 1y1 - the y-coordinate of point 1x2 - the x-coordinate of point 2y2 - the y-coordinate of point 2epsilon - the measure of nearness
public final boolean isNear(Point2D p1,
Point2D p2,
double epsilon)
Returns true if points p1 and p2 have distance less than or equal to epsilon.
p1 - point 1p2 - point 2epsilon - the measure of nearness
public final boolean isNear(double[] p1,
double[] p2,
double epsilon)
Returns true if points p1 and p2 have distance less than or equal to epsilon.
p1 - point 1p2 - point 2epsilon - the measure of nearness
public final boolean isNear(float[] p1,
float[] p2,
double epsilon)
Returns true if points p1 and p2 have distance less than or equal to epsilon.
p1 - point 1p2 - point 2epsilon - the measure of nearness
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||