Purpose: A utility class that can be used to perform operations on 2D lines, triangles, and polygons.
About the System: This class will be used by a 2D renderer and a 3D renderer (and, perhaps, other classes).
Details
Vectors of Different Size:
Side Effects:
The area() Method:
/**
* Compute the area of a triangle from its three vertices
*
* The verteces can be assumed to be ordered correctly
* (i.e., obey the right-hand rule)
*
* @param a The first vertex
* @param b The second vertex
* @param c The third vertex
*/
public static double area(double[] a, double[] b, double[] c)
The intersect() Method:
/**
* Find the intersection of two lines
*
* This method returns null if the lines are parallel.
* Otherwise, it returns the (convex combination) weights
* that define the intersection point. Letting
* alpha denote the weight for line 0 and
* beta denote the weight for line 1, the intersection
* point is given by:
*
* x: alpha*p[0] + (1-alpha)*q[0]
* y: alpha*p[1] + (1-alpha)*q[1]
*
* and or:
*
* x: beta*r[0] + (1-beta)*s[0]
* y: beta*r[1] + (1-beta)*s[1]
*
* If alpha is in [0, 1] then the intersection point is
* within the line segment from p to q. Similarly,
* if beta is in [0, 1] then the intersection point is
* within the line segment from r to s.
*
* @param p One endpoint of the line from p to q
* @param q The other endpoint of the line from p to q
* @param r One endpoint of the line from r to s
* @param s The other endpoint of the line from r to s
* @return The weights (alpha,beta) or null if the lines are parallel
*/
public static double[] intersect(double[] p, double[] q,
double[] r, double[] s)
Copyright 2007