unlekker.geom
Class Intersect

java.lang.Object
  extended by unlekker.geom.Intersect

public class Intersect
extends java.lang.Object

Geometry utilities. Intersections, collisions etc.


Field Summary
static float intersectX
          The point of intersection, if any.
static float intersectY
          The point of intersection, if any.
static boolean isIntersecting
          Indicates the result of the last intersection check.
 
Constructor Summary
Intersect()
           
 
Method Summary
static boolean insidePolygon(float x, float y, float[] poly)
          Calculates whether a point is inside a 2D polygon.
static boolean intersect(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
          Calculates the intersection between two lines.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

intersectX

public static float intersectX
The point of intersection, if any.


intersectY

public static float intersectY
The point of intersection, if any.


isIntersecting

public static boolean isIntersecting
Indicates the result of the last intersection check.

Constructor Detail

Intersect

public Intersect()
Method Detail

intersect

public static boolean intersect(float x1,
                                float y1,
                                float x2,
                                float y2,
                                float x3,
                                float y3,
                                float x4,
                                float y4)
Calculates the intersection between two lines.

Returns:
Returns true if there is an intersection, in which case intersectX and intersectY will contain the actual point of intersection. Returns false otherwise. This code comes from a post on Code & Form, which led to a response with a more efficient algorithm taken from Graphics Gems. See the original discussion.

insidePolygon

public static boolean insidePolygon(float x,
                                    float y,
                                    float[] poly)
Calculates whether a point is inside a 2D polygon.

Parameters:
x,y - The point to check.
poly - Array containing the pairs of X,Y coordinates that define the polygon. Must be in the correct order.
Returns:
Returns true if the point is inside the polygon. Returns false otherwise. Code is borrowed from this Processing.org thread. Thanks to st33d for the code.