edu.umd.cfar.lamp.viper.geometry
Class Util

java.lang.Object
  extended byedu.umd.cfar.lamp.viper.geometry.Util

public final class Util
extends java.lang.Object

A set of utility static methods for dealing with the viper geometry package.


Constructor Summary
Util()
           
 
Method Summary
static Rational areaSign(Component a, Component b, Component c)
          Calculates a minus b cross a minus c, or (a-b)x(a-c).
static boolean collinear(Pnt a, Pnt b, Pnt c)
          Checks to see if three points are collinear.
static boolean collinearAndOverlap(Pnt a, Pnt b, Pnt c, Pnt d)
          Tests to see if two line segments are collinear and overlap.
static double euclideanDistance(Pnt a, Pnt b)
          Computes the 2-norm of the distance between two points.
static char lineIntersection(Pnt a, Pnt b, Pnt c, Pnt d, Pnt p)
          Sets point p to the intersection of segments ab and cd.
static Rational manhattanDistance(Pnt a, Pnt b)
          Computes the 1-norm of the distance between two points.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

lineIntersection

public static char lineIntersection(Pnt a,
                                    Pnt b,
                                    Pnt c,
                                    Pnt d,
                                    Pnt p)
Sets point p to the intersection of segments ab and cd.

Parameters:
a - endpoint of the first line
b - endpoint of the first line
c - endpoint of the second line
d - endpoint of the second line
p - the point that will be modified to refer to the point of intersection. It is only modified if the two lines intersect.
Returns:
'e'
The segments collinearly overlap, sharing a point.
'v'
An endpoint (vertex) of one segment is on the other segment, but 'e' doesn't hold.
'1'
The segments intersect properly (i.e., they share a point and neither 'v' nor 'e' holds).
'0'
The segments do not intersect (i.e., they share no points).
Note that two collinear segments that share just one point, an endpoint of each, returns 'e' rather than 'v' as one might expect.

collinearAndOverlap

public static boolean collinearAndOverlap(Pnt a,
                                          Pnt b,
                                          Pnt c,
                                          Pnt d)
Tests to see if two line segments are collinear and overlap.

Parameters:
a - endpoint of the first line
b - endpoint of the first line
c - endpoint of the second line
d - endpoint of the second line
Returns:
true iff the segments ab and cd share at least one point and are collinear.

collinear

public static boolean collinear(Pnt a,
                                Pnt b,
                                Pnt c)
Checks to see if three points are collinear.

Parameters:
a - point to check
b - point to check
c - point to check
Returns:
true iff the three points lie on the same line.

areaSign

public static Rational areaSign(Component a,
                                Component b,
                                Component c)
Calculates a minus b cross a minus c, or (a-b)x(a-c). By the right hand rule, this returns positive values when a is to the left of bc and negative when it is to the right. The absolute value is the area of the parallelogram with points a, b, and c.

Parameters:
a - The origin of the parallelogram
b - The second point on the line
c - The third point.
Returns:
negative value if the three points are oriented clockwise, positive if CCW, and 0 if collinear.

manhattanDistance

public static Rational manhattanDistance(Pnt a,
                                         Pnt b)
Computes the 1-norm of the distance between two points.

Parameters:
a - A point
b - A point
Returns:
The sum of the x and y differences between points a and b

euclideanDistance

public static double euclideanDistance(Pnt a,
                                       Pnt b)
Computes the 2-norm of the distance between two points.

Parameters:
a - A point
b - A point
Returns:
The length of the line connecting a and b