PlaneF

Engine/source/math/mPlane.h

A 3D plane defined by a normal and a distance along the normal.

More...

Intersection

enum
Side {
  Front = 1
  On = 0
  Back = -1
}

Compute on which side of the plane the given point lies.

Compute which side the given sphere lies on.

Compute which side the given AABB lies on.

Compute which side the given OBB lies on.

whichSideBox(const Point3F & center, const Point3F & axisx, const Point3F & axisy, const Point3F & axisz)

Compute which side the given box lies on.

Compute the distance at which the ray traveling from start in the direction of @end intersects the plane.

bool
intersect(const Point3F & start, const Point3F & dir, Point3F * outHit)
bool
intersect(const PlaneF & plane, Point3F & outLineOrigin, Point3F & outLineDirection)

Compute the intersection between two planes.

Initialization

PlaneF(F32 _x, F32 _y, F32 _z, F32 _d)

NOTE: d is the NEGATIVE distance along the xyz normal.

set(F32 _x, F32 _y, F32 _z)
set(F32 _x, F32 _y, F32 _z, F32 _d)

NOTE: d is the NEGATIVE distance along the xyz normal.

Calculate the coefficients of the plane passing through a point with the given normal.

Clipping

clipPolygon(const Point3F * inVertices, U32 inNumVertices, Point3F * outVertices)

Clip a convex polygon by the plane.

bool
clipSegment(const Point3F & start, const Point3F & end, Point3F & outNewEnd)

Clip a line segment by the plane.

Public Attributes

d 

NEGATIVE distance along the xyz normal.

Public Functions

Return the distance of the given point from the plane.

Return the plane's normal.

Return the plane's position.

bool
bool
isParallelTo(const PlaneF & plane, F32 epsilon)
bool
isPerpendicularTo(const PlaneF & plane, F32 epsilon)
bool

Project the given point onto the plane.

Detailed Description

A 3D plane defined by a normal and a distance along the normal.

note:

The distance is stored negative.

Intersection

Side

Enumerator

Front = 1
On = 0
Back = -1
whichSide(const Point3F & cp)

Compute on which side of the plane the given point lies.

whichSide(const SphereF & sphere)

Compute which side the given sphere lies on.

whichSide(const Box3F & aabb)

Compute which side the given AABB lies on.

whichSide(const OrientedBox3F & obb)

Compute which side the given OBB lies on.

whichSideBox(const Point3F & center, const Point3F & axisx, const Point3F & axisy, const Point3F & axisz)

Compute which side the given box lies on.

Parameters:

center

Center point.

axisx

X-Axis vector. Length is box half-extent along X.

axisy

Y-Axis vector. Length is box half-extent along Y.

axisz

Z-Axis vector. Length is box half-extent along Z.

return:

Side that the given box is on.

intersect(const Point3F & start, const Point3F & end)

Compute the distance at which the ray traveling from start in the direction of @end intersects the plane.

Parameters:

start

Starting point of the ray.

end

Point in the direction of which the ray travels from start.

return:

The distance (as a fraction/multiple of the length of the vector between start and end) at which the ray intersects the plane or PARALLEL_PLANE if the ray is parallel to the plane.

intersect(const Point3F & start, const Point3F & dir, Point3F * outHit)

intersect(const PlaneF & plane, Point3F & outLineOrigin, Point3F & outLineDirection)

Compute the intersection between two planes.

Parameters:

plane

Plane to intersect with.

outLineOrigin

Used to store the origin of the resulting intersection line.

outLineDirection

Used to store the direction of the resulting intersection line.

return:

True if there is an intersection or false if the two planes are coplanar.

Initialization

PlaneF()

PlaneF(const Point3F & p, const Point3F & n)

PlaneF(F32 _x, F32 _y, F32 _z, F32 _d)

NOTE: d is the NEGATIVE distance along the xyz normal.

PlaneF(const Point3F & j, const Point3F & k, const Point3F & l)

set(F32 _x, F32 _y, F32 _z)

set(F32 _x, F32 _y, F32 _z, F32 _d)

NOTE: d is the NEGATIVE distance along the xyz normal.

set(const Point3F & p, const Point3F & n)

set(const Point3F & k, const Point3F & j, const Point3F & l)

setPoint(const Point3F & p)

Calculate the coefficients of the plane passing through a point with the given normal.

setXY(F32 zz)

setYZ(F32 xx)

setXZ(F32 yy)

setXY(const Point3F & P, F32 dir)

setYZ(const Point3F & P, F32 dir)

setXZ(const Point3F & P, F32 dir)

Clipping

clipPolygon(const Point3F * inVertices, U32 inNumVertices, Point3F * outVertices)

Clip a convex polygon by the plane.

The resulting polygon will be the input polygon minus the part on the negative side of the plane. The input polygon must be convex and inVertices must be in CCW or CW order.

Parameters:

inVertices

Array holding the vertices of the input polygon.

inNumVertices

Number of vertices in inVertices.

outVertices

Array to hold the vertices of the clipped polygon. Must have space for one additional vertex in case the polygon is split by the plane such that an additional vertex appears. Must not be the same as inVertices.

return:

Number of vertices in the clipped polygon, i.e. number of vertices in outVertices.

note:

Be aware that if the polygon fully lies on the negative side of the plane, the resulting outNumVertices will be zero, i.e. no polygon will result from the clip.

clipSegment(const Point3F & start, const Point3F & end, Point3F & outNewEnd)

Clip a line segment by the plane.

Parameters:

start

Start point of the line segment.

end

End point of the line segment.

outNewEnd

New end point if there is an intersection with the plane.

return:

True

Public Attributes

F32 d 

NEGATIVE distance along the xyz normal.

Public Functions

distToPlane(const Point3F & cp)

Return the distance of the given point from the plane.

getNormal()

Return the plane's normal.

getPosition()

Return the plane's position.

invert()

isHorizontal()

isParallelTo(const PlaneF & plane, F32 epsilon)

isPerpendicularTo(const PlaneF & plane, F32 epsilon)

isVertical()

neg()

project(const Point3F & pt)

Project the given point onto the plane.

shiftX(F32 xx)

shiftY(F32 yy)

shiftZ(F32 zz)