CrystalSpace

Public API Reference

Static Public Member Functions
csIntersect3 Class Reference

Some functions to perform various intersection calculations with 3D line segments. More...

#include <csgeom/math3d.h>

List of all members.

Static Public Member Functions

static bool BoxBox (const csBox3 &box1, const csBox3 &box2)
 Test if two boxes intersect.
static bool BoxFrustum (const csBox3 &box, const csPlane3 *frustum, uint32 inClipMask, uint32 &outClipMask)
 Intersect an AABB with a frustum.
static bool BoxFrustum (const csBox3 &box, const csFrustum *frustum)
 Intersect an AABB with a frustum.
static bool BoxPlane (const csBox3 &box, const csPlane3 &plane)
 Test if a plane intersects with a box.
static bool BoxPlane (const csBox3 &box, const csVector3 &normal, const csVector3 &vert)
 Test if a plane intersects with a box.
static int BoxSegment (const csBox3 &box, const csSegment3 &segment, csVector3 &isect, float *pr=0, bool use_ray=false)
 Intersect a segment or ray with a box.
static bool BoxSphere (const csBox3 &box, const csVector3 &center, float sqradius)
 Test if a box intersects with a sphere.
static bool BoxTriangle (const csBox3 &box, const csVector3 &tri0, const csVector3 &tri1, const csVector3 &tri2)
 Test if a triangle intersects with a box.
static bool ClipSegmentBox (csSegment3 &segment, const csBox3 &box, bool use_ray=false)
 Clip a segment or ray to a box.
static csPtr< csFrustum > FrustumFrustum (const csFrustum &f1, const csFrustum &f2)
 Calculate intersection of two frustums.
static csPtr< csFrustum > FrustumFrustum (const csFrustum &f1, csVector3 *poly, int num)
 Calculate intersection of two frustums.
static bool PlaneAxisPlane (const csPlane3 &p1, int nr, float pos, csPlane2 &isect)
 Intersect a regular plane and an axis aligned plane and return the intersection (line) as a 2D plane.
static bool PlanePolygon (const csPlane3 &plane, csPoly3D *poly, csSegment3 &segment)
 Intersect a plane with a 3D polygon and return the line segment corresponding with this intersection.
static bool PlaneXPlane (const csPlane3 &p1, float x2, csPlane2 &isect)
 Intersect a regular plane and an axis aligned plane and return the intersection (line) as a 2D plane.
static bool PlaneYPlane (const csPlane3 &p1, float y2, csPlane2 &isect)
 Intersect a regular plane and an axis aligned plane and return the intersection (line) as a 2D plane.
static bool PlaneZPlane (const csPlane3 &p1, float z2, csPlane2 &isect)
 Intersect a regular plane and an axis aligned plane and return the intersection (line) as a 2D plane.
static float SegmentAxisPlane (const csVector3 &u, const csVector3 &v, int nr, float pos, csVector3 &isect)
 Intersect a 3D segment with an axis aligned plane and return the intersection (fails if segment is parallel to the plane), and returns the distance from u to the intersection point.
static int SegmentFrustum (csPlane3 *planes, int num_planes, csSegment3 &seg)
 Intersect a segment with a frustum (given as a set of planes).
static bool SegmentPlane (const csVector3 &u, const csVector3 &v, const csVector3 &normal, const csVector3 &a, csVector3 &isect, float &dist)
 Intersect a 3D segment with a plane.
static bool SegmentPlane (const csPlane3 &plane, csSegment3 &segment)
 Intersect a 3D segment with a plane.
static bool SegmentPlane (const csVector3 &u, const csVector3 &v, const csPlane3 &p, csVector3 &isect, float &dist)
 Intersect a 3D segment with a plane.
static bool SegmentPlanes (const csVector3 &u, const csVector3 &v, const csPlane3 *planes, int length, csVector3 &isect, float &dist)
 If a number of planes enclose a convex space (with their normals pointing outwards).
static bool SegmentPolygon (const csSegment3 &seg, const csPoly3D &poly, const csPlane3 &poly_plane, csVector3 &isect)
 Intersect a 3D segment with a polygon.
static bool SegmentTriangle (const csSegment3 &seg, const csVector3 &tr1, const csVector3 &tr2, const csVector3 &tr3, csVector3 &isect)
 Intersect a 3D segment with a triangle.
static float SegmentXFrustum (const csVector3 &u, const csVector3 &v, float A, csVector3 &isect)
 Intersect a 3D segment with the frustum plane Ax + z = 0.
static float SegmentXFrustum (const csSegment3 &uv, float A, csVector3 &isect)
 Intersect a 3D segment with the frustum plane Ax + z = 0.
static float SegmentXPlane (const csVector3 &u, const csVector3 &v, float xval, csVector3 &isect)
 Intersect a 3D segment with the plane x = xval.
static float SegmentXPlane (const csSegment3 &uv, float xval, csVector3 &isect)
 Intersect a 3D segment with the plane x = xval.
static float SegmentYFrustum (const csVector3 &u, const csVector3 &v, float B, csVector3 &isect)
 Intersect a 3D segment with the frustum plane By + z = 0.
static float SegmentYFrustum (const csSegment3 &uv, float B, csVector3 &isect)
 Intersect a 3D segment with the frustum plane By + z = 0.
static float SegmentYPlane (const csVector3 &u, const csVector3 &v, float yval, csVector3 &isect)
 Intersect a 3D segment with the plane y = yval.
static float SegmentYPlane (const csSegment3 &uv, float yval, csVector3 &isect)
 Intersect a 3D segment with the plane y = yval.
static float SegmentZ0Plane (const csVector3 &v1, const csVector3 &v2, csVector3 &isect)
 Intersect a 3D segment with the z = 0 plane.
static float SegmentZ0Plane (const csSegment3 &uv, csVector3 &isect)
 Intersect a 3D segment with the z = 0 plane.
static float SegmentZPlane (const csVector3 &u, const csVector3 &v, float zval, csVector3 &isect)
 Intersect a 3D segment with the plane z = zval.
static float SegmentZPlane (const csSegment3 &uv, float zval, csVector3 &isect)
 Intersect a 3D segment with the plane z = zval.
static bool ThreePlanes (const csPlane3 &p1, const csPlane3 &p2, const csPlane3 &p3, csVector3 &isect)
 Intersect 3 planes to get the point that is part of all three planes.
static bool TriangleTriangle (const csVector3 tri1[3], const csVector3 tri2[3])
 Test intersection between two triangles.
static bool TriangleTriangle (const csVector3 tri1[3], const csVector3 tri2[3], csSegment3 &isectline, bool &coplanar)
 Calculate intersection between two triangles and return it in isectline.

Detailed Description

Some functions to perform various intersection calculations with 3D line segments.

This is a static class and contains only static member functions.

Definition at line 261 of file math3d.h.


Member Function Documentation

static bool csIntersect3::BoxBox ( const csBox3 &  box1,
const csBox3 &  box2 
) [inline, static]

Test if two boxes intersect.

Definition at line 648 of file math3d.h.

static bool csIntersect3::BoxFrustum ( const csBox3 &  box,
const csPlane3 *  frustum,
uint32  inClipMask,
uint32 &  outClipMask 
) [static]

Intersect an AABB with a frustum.

The frustum may contain up to 32 planes. Active planes are defined using the 'inClipMask'. It will return true if AABB is visible in frustum. If the AABB intersects with the frustum then 'outClipMask' will contain the mask for all planes intersecting with the AABB. This can be used as 'inClipMask' for subsequent frustum tests with children of the AABB (i.e. other AABB inside this AABB).

static bool csIntersect3::BoxFrustum ( const csBox3 &  box,
const csFrustum *  frustum 
) [static]

Intersect an AABB with a frustum.

static bool csIntersect3::BoxPlane ( const csBox3 &  box,
const csPlane3 &  plane 
) [static]

Test if a plane intersects with a box.

static bool csIntersect3::BoxPlane ( const csBox3 &  box,
const csVector3 &  normal,
const csVector3 &  vert 
) [static]

Test if a plane intersects with a box.

'vert' is one point on the plane.

static int csIntersect3::BoxSegment ( const csBox3 &  box,
const csSegment3 &  segment,
csVector3 &  isect,
float *  pr = 0,
bool  use_ray = false 
) [static]

Intersect a segment or ray with a box.

If the segment starts inside the box then isect will return the start of the segment.

Parameters:
boxThe box with which to perform the intersection.
segmentThe intersection candidate.
isectThe returned intersection point.
prIf not null then a number between 0 and 1 (or bigger then 1 in case we are doing ray testing) is returned which corresponds to the position on the segment or ray. If we were in the box this this function will return CS_BOX_INSIDE. In this case 'isect' will be set to the start of the segment and *pr to 0.
use_rayif true then the test is done as if the segment is a ray starting at the start of the segment and going in the direction of the end of the segment. Default is false.
Returns:
one of CS_BOX_SIDE_... if it intersects, CS_BOX_INSIDE if inside, or -1 otherwise.
static bool csIntersect3::BoxSphere ( const csBox3 &  box,
const csVector3 &  center,
float  sqradius 
) [static]

Test if a box intersects with a sphere.

The intersection is not computed. The sphere is given with squared radius.

static bool csIntersect3::BoxTriangle ( const csBox3 &  box,
const csVector3 &  tri0,
const csVector3 &  tri1,
const csVector3 &  tri2 
) [static]

Test if a triangle intersects with a box.

static bool csIntersect3::ClipSegmentBox ( csSegment3 &  segment,
const csBox3 &  box,
bool  use_ray = false 
) [static]

Clip a segment or ray to a box.

Parameters:
segmentIs the segment or ray. It will be modified (if this routine returns true) to give the clipped segment.
boxis the box to clip against.
use_rayif true then the test is done with a ray instead of a segment. Default is false.
static csPtr<csFrustum> csIntersect3::FrustumFrustum ( const csFrustum &  f1,
const csFrustum &  f2 
) [inline, static]

Calculate intersection of two frustums.

Definition at line 656 of file math3d.h.

static csPtr<csFrustum> csIntersect3::FrustumFrustum ( const csFrustum &  f1,
csVector3 *  poly,
int  num 
) [inline, static]

Calculate intersection of two frustums.

Definition at line 665 of file math3d.h.

static bool csIntersect3::PlaneAxisPlane ( const csPlane3 &  p1,
int  nr,
float  pos,
csPlane2 &  isect 
) [inline, static]

Intersect a regular plane and an axis aligned plane and return the intersection (line) as a 2D plane.

This intersection is defined on the axis aligned plane.

Returns:
false if there is no intersection.

Definition at line 409 of file math3d.h.

static bool csIntersect3::PlanePolygon ( const csPlane3 &  plane,
csPoly3D *  poly,
csSegment3 &  segment 
) [static]

Intersect a plane with a 3D polygon and return the line segment corresponding with this intersection.

Returns true if there is an intersection. If false then 'segment' will not be valid.

static bool csIntersect3::PlaneXPlane ( const csPlane3 &  p1,
float  x2,
csPlane2 &  isect 
) [static]

Intersect a regular plane and an axis aligned plane and return the intersection (line) as a 2D plane.

This intersection is defined on the axis aligned plane.

Returns:
false if there is no intersection.
static bool csIntersect3::PlaneYPlane ( const csPlane3 &  p1,
float  y2,
csPlane2 &  isect 
) [static]

Intersect a regular plane and an axis aligned plane and return the intersection (line) as a 2D plane.

This intersection is defined on the axis aligned plane.

Returns:
false if there is no intersection.
static bool csIntersect3::PlaneZPlane ( const csPlane3 &  p1,
float  z2,
csPlane2 &  isect 
) [static]

Intersect a regular plane and an axis aligned plane and return the intersection (line) as a 2D plane.

This intersection is defined on the axis aligned plane.

Returns:
false if there is no intersection.
static float csIntersect3::SegmentAxisPlane ( const csVector3 &  u,
const csVector3 &  v,
int  nr,
float  pos,
csVector3 &  isect 
) [inline, static]

Intersect a 3D segment with an axis aligned plane and return the intersection (fails if segment is parallel to the plane), and returns the distance from u to the intersection point.

The intersection point is returned in isect.

Definition at line 525 of file math3d.h.

static int csIntersect3::SegmentFrustum ( csPlane3 *  planes,
int  num_planes,
csSegment3 &  seg 
) [static]

Intersect a segment with a frustum (given as a set of planes).

Returns the clipped segment (i.e. the part of the segment that is visible in the frustum). Returns -1 if the segment is entirely outside the frustum. Returns 0 if the segment is not modified and returns 1 otherwise. The input segment will be modified. @@ WARNING! This function may not work completely ok. It has only barely been tested and is now unused.

static bool csIntersect3::SegmentPlane ( const csVector3 &  u,
const csVector3 &  v,
const csVector3 &  normal,
const csVector3 &  a,
csVector3 &  isect,
float &  dist 
) [static]

Intersect a 3D segment with a plane.

Returns:
true if there is an intersection, with the intersection point returned in isect.
static bool csIntersect3::SegmentPlane ( const csPlane3 &  plane,
csSegment3 &  segment 
) [static]

Intersect a 3D segment with a plane.

Returns:
true if there is an intersection, segment updated to reflect the clipped part.
static bool csIntersect3::SegmentPlane ( const csVector3 &  u,
const csVector3 &  v,
const csPlane3 &  p,
csVector3 &  isect,
float &  dist 
) [static]

Intersect a 3D segment with a plane.

Returns true if there is an intersection, with the intersection point returned in isect. The distance from u to the intersection point is returned in dist. The distance that is returned is a normalized distance with respect to the given input vector. i.e. a distance of 0.5 means that the intersection point is halfway u and v. There are two cases in which this method will return false:

  • If the plane and the segment are parallel, then 'dist' will be set equal to 0, and 'isect' equal to 'v'.
  • If the segment does not cross the plane (i.e. if 'dist'>1+epsilon or 'dist'<-epsilon, where epsilon is a very small value near to zero) then 'isect's value is (0, 0, 0).
Remarks:
'p' is the plane, expressed as: A x + B y + C z + D = 0 , where (A,B,C) is the normal vector of the plane. 'u' and 'v' are the start (U point) and the end (V point) of the segment. 'isect' is searched along the segment U + x (V - U); the unknown 'x' value is got by: x = [(A,B,C) * U + D ] / (A,B,C) * (U - V), where * is the dot product.
static bool csIntersect3::SegmentPlanes ( const csVector3 &  u,
const csVector3 &  v,
const csPlane3 *  planes,
int  length,
csVector3 &  isect,
float &  dist 
) [static]

If a number of planes enclose a convex space (with their normals pointing outwards).

Returns:
true if they are intersected by a segment. isect contains the closest intersection point. dist contains the distance to that point (with distance between u and v being 1)
static bool csIntersect3::SegmentPolygon ( const csSegment3 &  seg,
const csPoly3D &  poly,
const csPlane3 &  poly_plane,
csVector3 &  isect 
) [static]

Intersect a 3D segment with a polygon.

Returns:
true if there is an intersection. In that case the intersection point will be in 'isect'. Note that this function doesn't do backface culling.
static bool csIntersect3::SegmentTriangle ( const csSegment3 &  seg,
const csVector3 &  tr1,
const csVector3 &  tr2,
const csVector3 &  tr3,
csVector3 &  isect 
) [static]

Intersect a 3D segment with a triangle.

Returns:
true if there is an intersection. In that case the intersection point will be in 'isect'.
static float csIntersect3::SegmentXFrustum ( const csVector3 &  u,
const csVector3 &  v,
float  A,
csVector3 &  isect 
) [static]

Intersect a 3D segment with the frustum plane Ax + z = 0.

Assumes an intersection, and returns the intersection point in isect.

static float csIntersect3::SegmentXFrustum ( const csSegment3 &  uv,
float  A,
csVector3 &  isect 
) [inline, static]

Intersect a 3D segment with the frustum plane Ax + z = 0.

Assumes an intersection, and returns the intersection point in isect.

Definition at line 548 of file math3d.h.

static float csIntersect3::SegmentXPlane ( const csVector3 &  u,
const csVector3 &  v,
float  xval,
csVector3 &  isect 
) [static]

Intersect a 3D segment with the plane x = xval.

Assumes that there is an intersection (fails if the segment is parallel to the plane), and returns the distance from u to the intersection point. The intersection point is returned in isect.

static float csIntersect3::SegmentXPlane ( const csSegment3 &  uv,
float  xval,
csVector3 &  isect 
) [inline, static]

Intersect a 3D segment with the plane x = xval.

Assumes that there is an intersection (fails if the segment is parallel to the plane), and returns the distance from u to the intersection point. The intersection point is returned in isect.

Definition at line 461 of file math3d.h.

static float csIntersect3::SegmentYFrustum ( const csVector3 &  u,
const csVector3 &  v,
float  B,
csVector3 &  isect 
) [static]

Intersect a 3D segment with the frustum plane By + z = 0.

Assumes an intersection, and returns the intersection point in isect.

static float csIntersect3::SegmentYFrustum ( const csSegment3 &  uv,
float  B,
csVector3 &  isect 
) [inline, static]

Intersect a 3D segment with the frustum plane By + z = 0.

Assumes an intersection, and returns the intersection point in isect.

Definition at line 565 of file math3d.h.

static float csIntersect3::SegmentYPlane ( const csVector3 &  u,
const csVector3 &  v,
float  yval,
csVector3 &  isect 
) [static]

Intersect a 3D segment with the plane y = yval.

Assumes that there is an intersection (fails if the segment is parallel to the plane), and returns the distance from u to the intersection point. The intersection point is returned in isect.

static float csIntersect3::SegmentYPlane ( const csSegment3 &  uv,
float  yval,
csVector3 &  isect 
) [inline, static]

Intersect a 3D segment with the plane y = yval.

Assumes that there is an intersection (fails if the segment is parallel to the plane), and returns the distance from u to the intersection point. The intersection point is returned in isect.

Definition at line 486 of file math3d.h.

static float csIntersect3::SegmentZ0Plane ( const csVector3 &  v1,
const csVector3 &  v2,
csVector3 &  isect 
) [static]

Intersect a 3D segment with the z = 0 plane.

Assumes that there is an intersection (fails if the segment is parallel to the plane), and returns the distance from u to the intersection point. The intersection point is returned in isect.

static float csIntersect3::SegmentZ0Plane ( const csSegment3 &  uv,
csVector3 &  isect 
) [inline, static]

Intersect a 3D segment with the z = 0 plane.

Assumes that there is an intersection (fails if the segment is parallel to the plane), and returns the distance from u to the intersection point. The intersection point is returned in isect.

Definition at line 437 of file math3d.h.

static float csIntersect3::SegmentZPlane ( const csVector3 &  u,
const csVector3 &  v,
float  zval,
csVector3 &  isect 
) [static]

Intersect a 3D segment with the plane z = zval.

Assumes that there is an intersection (fails if the segment is parallel to the plane), and returns the distance from u to the intersection point. The intersection point is returned in isect.

static float csIntersect3::SegmentZPlane ( const csSegment3 &  uv,
float  zval,
csVector3 &  isect 
) [inline, static]

Intersect a 3D segment with the plane z = zval.

Assumes that there is an intersection (fails if the segment is parallel to the plane), and returns the distance from u to the intersection point. The intersection point is returned in isect.

Definition at line 511 of file math3d.h.

static bool csIntersect3::ThreePlanes ( const csPlane3 &  p1,
const csPlane3 &  p2,
const csPlane3 &  p3,
csVector3 &  isect 
) [static]

Intersect 3 planes to get the point that is part of all three planes.

Returns:
true if there is a single point that fits. If some planes are parallel, then it will return false.
static bool csIntersect3::TriangleTriangle ( const csVector3  tri1[3],
const csVector3  tri2[3] 
) [static]

Test intersection between two triangles.

Parameters:
tri1Vertices of triangle 1
tri2Vertices of triangle 2
Returns:
true if the triangles intersect, otherwise false
static bool csIntersect3::TriangleTriangle ( const csVector3  tri1[3],
const csVector3  tri2[3],
csSegment3 &  isectline,
bool &  coplanar 
) [static]

Calculate intersection between two triangles and return it in isectline.

Parameters:
tri1Vertices of triangle 1
tri2Vertices of triangle 2
[out]isectlineThe line segment where they intersect
[out]coplanarReturns whether the triangles are coplanar
Returns:
true if the triangles intersect, otherwise false

The documentation for this class was generated from the following file:

Generated for Crystal Space 2.0 by doxygen 1.7.6.1