computational.geometry
Class BasicTests

java.lang.Object
  extended by computational.geometry.BasicTests

public class BasicTests
extends java.lang.Object


Method Summary
static boolean between(Point s0, Point s1, Point p)
          Tests if a point lies on a line segment.
static boolean between(Segment s, Point p)
          Tests if a point lies on a line segment.
static boolean collinear(Point p0, Point p1, Point p2)
          Tests collinearity between three points.
static int crossProduct(int x0, int y0, int x1, int y1)
          Computes the cross-product (i.e.
static int crossProduct(Point p0, Point p1)
          Computes the cross-product of two vectors.
static boolean intersect(Segment s, Segment t)
          Tests if two segments intersect.
static boolean intersectProperly(Segment s, Segment t)
          Tests if two segments intersect properly.
static boolean sameSide(Point p0, Point p1, Segment s)
          Tests whether two points are on the same side of the half-plane defined by a segment.
static int turns(Point p0, Point p1, Point p2)
          Determines whether two consecutive line segments form a left turn, a right turn or they are collinear.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

between

public static boolean between(Point s0,
                              Point s1,
                              Point p)
Tests if a point lies on a line segment.

Parameters:
s0 - the segment's first endpoint.
s1 - the segment's second endpoint.
p - the point.
Returns:
true if p lies on segment (s0,s1), false otherwise. The segment is considered closed, that is p is said to lie on (s0,s1) if p equals one of its endpoints.

between

public static boolean between(Segment s,
                              Point p)
Tests if a point lies on a line segment.

Parameters:
s - the segment.
p - the point.
Returns:
true if p lies on segment s, false otherwise. The segment is considered closed, that is p is said to lie on s if p equals one of its endpoints.

collinear

public static boolean collinear(Point p0,
                                Point p1,
                                Point p2)
Tests collinearity between three points.

Parameters:
p0 - the first point.
p1 - the second point.
p2 - the third point.
Returns:
true if the three points are collinear, false otherwise.

crossProduct

public static int crossProduct(int x0,
                               int y0,
                               int x1,
                               int y1)
Computes the cross-product (i.e. vectorial product) of two vectors.

Warning: the X-axis is directed left to right, whether the Y-axis is directed top-down, contrary to the usual geometric conventions. To overcome this problem, we obtain the vectorial product of two points (x0,y0) and (x1,y1) by computing the determinant of the matrix:

i j k
x0 -y0 0
x1 -y1 0

Parameters:
x0 - the first vector's x-coordinate
y0 - the first vector's y-coordinate
x1 - the second vector's x-coordinate
y1 - the second vector's y-coordinate
Returns:
the cross-product of (x0,y0) and (x1,y1).

crossProduct

public static int crossProduct(Point p0,
                               Point p1)
Computes the cross-product of two vectors.

Parameters:
p0 - the first vector (represented as a Point)
p1 - the second vector (represented as a Point)
Returns:
the cross-product of p0 and p1.
See Also:
crossProduct(int,int,int,int)

intersect

public static boolean intersect(Segment s,
                                Segment t)
Tests if two segments intersect.

Parameters:
s - the first segment.
t - the second segment.
Returns:
true iff the two segments intersects (both properly or not), that is if their intersection is not empty.

intersectProperly

public static boolean intersectProperly(Segment s,
                                        Segment t)
Tests if two segments intersect properly.

Parameters:
s - the first segment.
t - the second segment.
Returns:
true iff the two segments intersects properly, that is if their intersection is made of an isolated point, and this point does not lie on one of the segments.

sameSide

public static boolean sameSide(Point p0,
                               Point p1,
                               Segment s)
Tests whether two points are on the same side of the half-plane defined by a segment.

Parameters:
p0 - the first point.
p1 - the second point.
s - the segment defining the half-plane.

turns

public static int turns(Point p0,
                        Point p1,
                        Point p2)
Determines whether two consecutive line segments form a left turn, a right turn or they are collinear.

Parameters:
p0 - the first segment's first endpoint.
p1 - the common endpoint between the two segments.
p2 - the second segment's second endpoint.
Returns:
the turn between (p0,p1) and (p1,p2).
See Also:
Turn