
j3d.org Code  
PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
java.lang.Object org.j3d.geom.IntersectionUtils
public class IntersectionUtils
A collection of utility methods to do geometry intersection tests.
The design of the implementation is focused towards realtime intersection requirements for collision detection and terrain following. We avoid the standard pattern of making the methods static because we believe that you may need multiple copies of this class floating around. Internally it will also seek to reduce the amount of garbage generated by allocating arrays of data and then maintaining those arrays between calls. Arrays are only resized if they need to get bigger. Smaller data than the currently allocated structures will use the existing data. For the same reason, we do not synchronise any of the methods. If you expect to have multiple threads needing to do intersection testing, we suggest you have separate copies of this class as no results are guaranteed if you are accessing this instance with multiple threads.
Calculation of the values works by configuring the class for the sort of data that you want returned. For the higher level methods that allow you
If you need the intersection tools for collision detection only, then you can tell the routines that you only need to know if they intersect. That is as soon as you detect one polygon that intersects, exit immediately. This is useful for doing collision detection because you really don't care where on the object you collide, just that you have.
The ray/polygon intersection test is a combination test. Firstly it will check for the segment intersection if requested. Then, for an infinite ray or an intersecting segment, we use the algorithm defined from the Siggraph paper in their education course:
Field Summary  

protected javax.vecmath.Vector3d 
pickDir

protected javax.vecmath.Point3d 
pickStart
Transformed pick items 
protected float[] 
wkPolygon
Working places for a single quad 
protected float[] 
working2dCoords
The current 2D coordinate list that we work from 
protected float[] 
workingCoords
The current coordinate list that we work from 
protected int[] 
workingIndicies

protected int[] 
workingStrips

static int 
X_AXIS
Cylinder intersection axis X 
static int 
Y_AXIS
Cylinder intersection axis Y 
static int 
Z_AXIS
Cylinder intersection axis Z 
Constructor Summary  

IntersectionUtils()
Create a default instance of this class with no internal data structures allocated. 
Method Summary  

void 
clear()
Clear the current internal structures to reduce the amount of memory used. 
boolean 
rayCylinder(float[] origin,
float[] direction,
int axis,
float[] cylAxis,
float cylRadius,
float[] point)
Compute the intersection point of the ray and an infinite cylinder. 
boolean 
rayCylinder(javax.vecmath.Point3d origin,
javax.vecmath.Vector3d direction,
int axis,
float[] cylAxis,
float cylRadius,
javax.vecmath.Point3d point)
Compute the intersection point of the ray and an infinite cylinder. 
boolean 
rayIndexedQuadArray(javax.vecmath.Point3d origin,
javax.vecmath.Vector3d direction,
float length,
float[] coords,
int[] indexes,
int numIndex,
javax.vecmath.Point3d point,
boolean intersectOnly)
Test an array of indexed quads for intersection. 
boolean 
rayIndexedTriangleArray(javax.vecmath.Point3d origin,
javax.vecmath.Vector3d direction,
float length,
float[] coords,
int[] indexes,
int numIndex,
javax.vecmath.Point3d point,
boolean intersectOnly)
Test an array of indexed triangles for intersection. 
boolean 
rayPlane(float[] origin,
float[] direction,
float[] plane,
float[] point)
Compute the intersection point of the ray and a plane. 
boolean 
rayPlane(javax.vecmath.Point3d origin,
javax.vecmath.Vector3d direction,
float[] plane,
javax.vecmath.Point3d point)
Compute the intersection point of the ray and a plane. 
boolean 
rayPolygon(javax.vecmath.Point3d origin,
javax.vecmath.Vector3d direction,
float length,
float[] coords,
int numCoords,
javax.vecmath.Point3d point)
Test to see if the polygon intersects with the given ray. 
boolean 
rayQuadArray(javax.vecmath.Point3d origin,
javax.vecmath.Vector3d direction,
float length,
float[] coords,
int numQuads,
javax.vecmath.Point3d point,
boolean intersectOnly)
Test an array of quads for intersection. 
boolean 
raySphere(float[] origin,
float[] direction,
float[] sphereCenter,
float sphereRadius,
float[] point)
Compute the intersection point of the ray and a sphere. 
boolean 
raySphere(javax.vecmath.Point3d origin,
javax.vecmath.Vector3d direction,
float[] sphereCenter,
float sphereRadius,
javax.vecmath.Point3d point)
Compute the intersection point of the ray and a sphere. 
boolean 
rayTriangleArray(javax.vecmath.Point3d origin,
javax.vecmath.Vector3d direction,
float length,
float[] coords,
int numTris,
javax.vecmath.Point3d point,
boolean intersectOnly)
Test an array of triangles for intersection. 
boolean 
rayTriangleFanArray(javax.vecmath.Point3d origin,
javax.vecmath.Vector3d direction,
float length,
float[] coords,
int[] stripCounts,
int numStrips,
javax.vecmath.Point3d point,
boolean intersectOnly)
Test an array of triangle fans for intersection. 
boolean 
rayTriangleStripArray(javax.vecmath.Point3d origin,
javax.vecmath.Vector3d direction,
float length,
float[] coords,
int[] stripCounts,
int numStrips,
javax.vecmath.Point3d point,
boolean intersectOnly)
Test an array of triangles strips for intersection. 
boolean 
rayUnknownGeometry(javax.vecmath.Point3d origin,
javax.vecmath.Vector3d direction,
float length,
GeometryData data,
javax.vecmath.Matrix4d vworldTransform,
javax.vecmath.Point3d point,
boolean intersectOnly)
Convenience method to process a GeometryData and ask the
intersection code to find out what the real geometry type is and
process it appropriately. 
Methods inherited from class java.lang.Object 

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait 
Field Detail 

public static final int X_AXIS
public static final int Y_AXIS
public static final int Z_AXIS
protected javax.vecmath.Point3d pickStart
protected javax.vecmath.Vector3d pickDir
protected float[] workingCoords
protected int[] workingStrips
protected int[] workingIndicies
protected float[] working2dCoords
protected float[] wkPolygon
Constructor Detail 

public IntersectionUtils()
Method Detail 

public void clear()
public boolean rayUnknownGeometry(javax.vecmath.Point3d origin, javax.vecmath.Vector3d direction, float length, GeometryData data, javax.vecmath.Matrix4d vworldTransform, javax.vecmath.Point3d point, boolean intersectOnly)
GeometryData
and ask the
intersection code to find out what the real geometry type is and
process it appropriately. If there is an intersection, the point will
contain the exact intersection point on the geometry.
This code will be much more efficient than the other version because we do not need to reallocate internal arrays all the time or have the need to set capability bits, hurting performance optimisations. If the geometry array does not understand the provided geometry type, it will silently ignore the request and always return false.
origin
 The origin of the raydirection
 The direction of the raylength
 An optional length for to make the ray a segment. If
the value is zero, it is ignoreddata
 The geometry to test againstpoint
 The intersection point for returningvworldTransform
 Transformation matrix to go from the root of the
world to this pointintersectOnly
 true if we only want to know if we have a
intersection and don't really care which it is
public boolean rayTriangleArray(javax.vecmath.Point3d origin, javax.vecmath.Vector3d direction, float length, float[] coords, int numTris, javax.vecmath.Point3d point, boolean intersectOnly)
origin
 The origin of the raydirection
 The direction of the raylength
 An optional length for to make the ray a segment. If
the value is zero, it is ignoredcoords
 The coordinates of the trianglesnumTris
 The number of triangles to use from the arraypoint
 The intersection point for returningintersectOnly
 true if we only want to know if we have a
intersection and don't really care which it is
public boolean rayQuadArray(javax.vecmath.Point3d origin, javax.vecmath.Vector3d direction, float length, float[] coords, int numQuads, javax.vecmath.Point3d point, boolean intersectOnly)
origin
 The origin of the raydirection
 The direction of the raylength
 An optional length for to make the ray a segment. If
the value is zero, it is ignoredcoords
 The coordinates of the quadsnumQuads
 The number of quads to use from the arraypoint
 The intersection point for returningintersectOnly
 true if we only want to know if we have a
intersection and don't really care which it is
public boolean rayTriangleStripArray(javax.vecmath.Point3d origin, javax.vecmath.Vector3d direction, float length, float[] coords, int[] stripCounts, int numStrips, javax.vecmath.Point3d point, boolean intersectOnly)
origin
 The origin of the raydirection
 The direction of the raylength
 An optional length for to make the ray a segment. If
the value is zero, it is ignoredcoords
 The coordinates of the trianglesstripCounts
 The number of polygons in each stripnumStrips
 The number of strips to use from the arraypoint
 The intersection point for returningintersectOnly
 true if we only want to know if we have a
intersection and don't really care which it is
public boolean rayTriangleFanArray(javax.vecmath.Point3d origin, javax.vecmath.Vector3d direction, float length, float[] coords, int[] stripCounts, int numStrips, javax.vecmath.Point3d point, boolean intersectOnly)
origin
 The origin of the raydirection
 The direction of the raylength
 An optional length for to make the ray a segment. If
the value is zero, it is ignoredcoords
 The coordinates of the trianglesstripCounts
 The number of polygons in each fannumStrips
 The number of strips to use from the arraypoint
 The intersection point for returningintersectOnly
 true if we only want to know if we have a
intersection and don't really care which it is
public boolean rayIndexedTriangleArray(javax.vecmath.Point3d origin, javax.vecmath.Vector3d direction, float length, float[] coords, int[] indexes, int numIndex, javax.vecmath.Point3d point, boolean intersectOnly)
origin
 The origin of the raydirection
 The direction of the raylength
 An optional length for to make the ray a segment. If
the value is zero, it is ignoredcoords
 The coordinates of the trianglesindexes
 The list of indexes to use to construct trianglesnumIndex
 The number of indexes to use from the arraypoint
 The intersection point for returningintersectOnly
 true if we only want to know if we have a
intersection and don't really care which it is
public boolean rayIndexedQuadArray(javax.vecmath.Point3d origin, javax.vecmath.Vector3d direction, float length, float[] coords, int[] indexes, int numIndex, javax.vecmath.Point3d point, boolean intersectOnly)
origin
 The origin of the raydirection
 The direction of the raylength
 An optional length for to make the ray a segment. If
the value is zero, it is ignoredcoords
 The coordinates of the trianglesindexes
 The list of indexes to use to construct trianglesnumIndex
 The number of indexes to use from the arraypoint
 The intersection point for returningintersectOnly
 true if we only want to know if we have a
intersection and don't really care which it is
public boolean rayCylinder(float[] origin, float[] direction, int axis, float[] cylAxis, float cylRadius, float[] point) throws java.lang.IllegalArgumentException
The cylAxis value refers to the coefficients for the axis of the
cylinder that does not pass through the origin. If we assume the
general equation for a cylinder that lies along the X axis is
(y  b)^2 + (z  c)^2 = r^2
then the values of this
parameter represent the coefficients (a, b, c). For the given axis,
only the two coefficients for the other axes are used.
origin
 The origin of the raydirection
 The direction of the rayaxis
 Identifier of which axis this is aligned tocylAxis
 The vector coefficients describing the axis of the cylindercylRadius
 The raduis of the cylinderpoint
 The intersection point for returning
java.lang.IllegalArgumentException
 The axis ID given is not validpublic boolean rayCylinder(javax.vecmath.Point3d origin, javax.vecmath.Vector3d direction, int axis, float[] cylAxis, float cylRadius, javax.vecmath.Point3d point) throws java.lang.IllegalArgumentException
The cylAxis value refers to the coefficients for the axis of the
cylinder that does not pass through the origin. If we assume the
general equation for a cylinder that lies along the X axis is
(y  b)^2 + (z  c)^2 = r^2
then the values of this
parameter represent the coefficients (a, b, c). For the given axis,
only the two coefficients for the other axes are used.
origin
 The origin of the raydirection
 The direction of the rayaxis
 Identifier of which axis this is aligned tocylAxis
 The vector coefficients describing the axis of the cylindercylRadius
 The raduis of the cylinderpoint
 The intersection point for returning
java.lang.IllegalArgumentException
 The axis ID given is not validpublic boolean raySphere(float[] origin, float[] direction, float[] sphereCenter, float sphereRadius, float[] point)
origin
 The origin of the raydirection
 The direction of the raysphereCenter
 The coordinates of the center of the spheresphereRadius
 The raduis of the spherepoint
 The intersection point for returning
public boolean raySphere(javax.vecmath.Point3d origin, javax.vecmath.Vector3d direction, float[] sphereCenter, float sphereRadius, javax.vecmath.Point3d point)
origin
 The origin of the raydirection
 The direction of the raysphereCenter
 The coordinates of the center of the spheresphereRadius
 The raduis of the spherepoint
 The intersection point for returning
public boolean rayPlane(float[] origin, float[] direction, float[] plane, float[] point)
origin
 The origin of the raydirection
 The direction of the rayplane
 The coefficients for the plane equation (ax + by + cz + d = 0)point
 The intersection point for returning
public boolean rayPlane(javax.vecmath.Point3d origin, javax.vecmath.Vector3d direction, float[] plane, javax.vecmath.Point3d point)
origin
 The origin of the raydirection
 The direction of the rayplane
 The coefficients for the plane equation (ax + by + cz + d = 0)point
 The intersection point for returning
public boolean rayPolygon(javax.vecmath.Point3d origin, javax.vecmath.Vector3d direction, float length, float[] coords, int numCoords, javax.vecmath.Point3d point)
origin
 The origin of the raydirection
 The direction of the raylength
 An optional length for to make the ray a segment. If
the value is zero, it is ignoredcoords
 The coordinates of the polygonnumCoords
 The number of coordinates to use from the arraypoint
 The intersection point for returning

j3d.org Code  
PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 