arsa  2.7
Public Member Functions | Public Attributes | List of all members
irr::core::plane3d< T > Class Template Reference

Template plane class with some intersection testing methods. More...

#include <plane3d.h>

Public Member Functions

 plane3d ()
 
 plane3d (const vector3d< T > &MPoint, const vector3d< T > &Normal)
 
 plane3d (T px, T py, T pz, T nx, T ny, T nz)
 
 plane3d (const vector3d< T > &point1, const vector3d< T > &point2, const vector3d< T > &point3)
 
 plane3d (const vector3d< T > &normal, const T d)
 
bool operator== (const plane3d< T > &other) const
 
bool operator!= (const plane3d< T > &other) const
 
void setPlane (const vector3d< T > &point, const vector3d< T > &nvector)
 
void setPlane (const vector3d< T > &nvect, T d)
 
void setPlane (const vector3d< T > &point1, const vector3d< T > &point2, const vector3d< T > &point3)
 
bool getIntersectionWithLine (const vector3d< T > &linePoint, const vector3d< T > &lineVect, vector3d< T > &outIntersection) const
 Get an intersection with a 3d line. More...
 
f32 getKnownIntersectionWithLine (const vector3d< T > &linePoint1, const vector3d< T > &linePoint2) const
 Get percentage of line between two points where an intersection with this plane happens. More...
 
bool getIntersectionWithLimitedLine (const vector3d< T > &linePoint1, const vector3d< T > &linePoint2, vector3d< T > &outIntersection) const
 Get an intersection with a 3d line, limited between two 3d points. More...
 
EIntersectionRelation3D classifyPointRelation (const vector3d< T > &point) const
 Classifies the relation of a point to this plane. More...
 
void recalculateD (const vector3d< T > &MPoint)
 Recalculates the distance from origin by applying a new member point to the plane. More...
 
vector3d< T > getMemberPoint () const
 Gets a member point of the plane. More...
 
bool existsIntersection (const plane3d< T > &other) const
 Tests if there is an intersection with the other plane. More...
 
bool getIntersectionWithPlane (const plane3d< T > &other, vector3d< T > &outLinePoint, vector3d< T > &outLineVect) const
 Intersects this plane with another. More...
 
bool getIntersectionWithPlanes (const plane3d< T > &o1, const plane3d< T > &o2, vector3d< T > &outPoint) const
 Get the intersection point with two other planes if there is one. More...
 
bool isFrontFacing (const vector3d< T > &lookDirection) const
 Test if the triangle would be front or backfacing from any point. More...
 
getDistanceTo (const vector3d< T > &point) const
 Get the distance to a point. More...
 

Public Attributes

vector3d< T > Normal
 Normal vector of the plane. More...
 
D
 Distance from origin. More...
 

Detailed Description

template<class T>
class irr::core::plane3d< T >

Template plane class with some intersection testing methods.

It has to be ensured, that the normal is always normalized. The constructors and setters of this class will not ensure this automatically. So any normal passed in has to be normalized in advance. No change to the normal will be made by any of the class methods.

Definition at line 33 of file plane3d.h.

Constructor & Destructor Documentation

◆ plane3d() [1/5]

template<class T>
irr::core::plane3d< T >::plane3d ( )
inline

Definition at line 39 of file plane3d.h.

39 : Normal(0,1,0) { recalculateD(vector3d<T>(0,0,0)); }
vector3d< T > Normal
Normal vector of the plane.
Definition: plane3d.h:228
void recalculateD(const vector3d< T > &MPoint)
Recalculates the distance from origin by applying a new member point to the plane.
Definition: plane3d.h:149

◆ plane3d() [2/5]

template<class T>
irr::core::plane3d< T >::plane3d ( const vector3d< T > &  MPoint,
const vector3d< T > &  Normal 
)
inline

Definition at line 41 of file plane3d.h.

41 : Normal(Normal) { recalculateD(MPoint); }
vector3d< T > Normal
Normal vector of the plane.
Definition: plane3d.h:228
void recalculateD(const vector3d< T > &MPoint)
Recalculates the distance from origin by applying a new member point to the plane.
Definition: plane3d.h:149

◆ plane3d() [3/5]

template<class T>
irr::core::plane3d< T >::plane3d ( px,
py,
pz,
nx,
ny,
nz 
)
inline

Definition at line 43 of file plane3d.h.

43 : Normal(nx, ny, nz) { recalculateD(vector3d<T>(px, py, pz)); }
vector3d< T > Normal
Normal vector of the plane.
Definition: plane3d.h:228
GLfixed ny
GLbyte nx
GLfixed GLfixed nz
void recalculateD(const vector3d< T > &MPoint)
Recalculates the distance from origin by applying a new member point to the plane.
Definition: plane3d.h:149

◆ plane3d() [4/5]

template<class T>
irr::core::plane3d< T >::plane3d ( const vector3d< T > &  point1,
const vector3d< T > &  point2,
const vector3d< T > &  point3 
)
inline

Definition at line 45 of file plane3d.h.

46  { setPlane(point1, point2, point3); }
void setPlane(const vector3d< T > &point, const vector3d< T > &nvector)
Definition: plane3d.h:58

◆ plane3d() [5/5]

template<class T>
irr::core::plane3d< T >::plane3d ( const vector3d< T > &  normal,
const d 
)
inline

Definition at line 48 of file plane3d.h.

48 : Normal(normal), D(d) { }
T D
Distance from origin.
Definition: plane3d.h:231
vector3d< T > Normal
Normal vector of the plane.
Definition: plane3d.h:228

Member Function Documentation

◆ classifyPointRelation()

template<class T>
EIntersectionRelation3D irr::core::plane3d< T >::classifyPointRelation ( const vector3d< T > &  point) const
inline

Classifies the relation of a point to this plane.

Parameters
pointPoint to classify its relation.
Returns
ISREL3D_FRONT if the point is in front of the plane, ISREL3D_BACK if the point is behind of the plane, and ISREL3D_PLANAR if the point is within the plane.

Definition at line 135 of file plane3d.h.

136  {
137  const T d = Normal.dotProduct(point) + D;
138 
139  if (d < -ROUNDING_ERROR_f32)
140  return ISREL3D_BACK;
141 
142  if (d > ROUNDING_ERROR_f32)
143  return ISREL3D_FRONT;
144 
145  return ISREL3D_PLANAR;
146  }
T D
Distance from origin.
Definition: plane3d.h:231
vector3d< T > Normal
Normal vector of the plane.
Definition: plane3d.h:228
const f32 ROUNDING_ERROR_f32
Definition: irrMath.h:50

◆ existsIntersection()

template<class T>
bool irr::core::plane3d< T >::existsIntersection ( const plane3d< T > &  other) const
inline

Tests if there is an intersection with the other plane.

Returns
True if there is a intersection.

Definition at line 162 of file plane3d.h.

163  {
164  vector3d<T> cross = other.Normal.crossProduct(Normal);
165  return cross.getLength() > core::ROUNDING_ERROR_f32;
166  }
vector3d< T > Normal
Normal vector of the plane.
Definition: plane3d.h:228
const f32 ROUNDING_ERROR_f32
Definition: irrMath.h:50

◆ getDistanceTo()

template<class T>
T irr::core::plane3d< T >::getDistanceTo ( const vector3d< T > &  point) const
inline

Get the distance to a point.

Note that this only works if the normal is normalized.

Definition at line 222 of file plane3d.h.

223  {
224  return point.dotProduct(Normal) + D;
225  }
T D
Distance from origin.
Definition: plane3d.h:231
vector3d< T > Normal
Normal vector of the plane.
Definition: plane3d.h:228

◆ getIntersectionWithLimitedLine()

template<class T>
bool irr::core::plane3d< T >::getIntersectionWithLimitedLine ( const vector3d< T > &  linePoint1,
const vector3d< T > &  linePoint2,
vector3d< T > &  outIntersection 
) const
inline

Get an intersection with a 3d line, limited between two 3d points.

Parameters
linePoint1Point 1 of the line.
linePoint2Point 2 of the line.
outIntersectionPlace to store the intersection point, if there is one.
Returns
True if there was an intersection, false if there was not.

Definition at line 121 of file plane3d.h.

125  {
126  return (getIntersectionWithLine(linePoint1, linePoint2 - linePoint1, outIntersection) &&
127  outIntersection.isBetweenPoints(linePoint1, linePoint2));
128  }
bool getIntersectionWithLine(const vector3d< T > &linePoint, const vector3d< T > &lineVect, vector3d< T > &outIntersection) const
Get an intersection with a 3d line.
Definition: plane3d.h:86

◆ getIntersectionWithLine()

template<class T>
bool irr::core::plane3d< T >::getIntersectionWithLine ( const vector3d< T > &  linePoint,
const vector3d< T > &  lineVect,
vector3d< T > &  outIntersection 
) const
inline

Get an intersection with a 3d line.

Parameters
lineVectVector of the line to intersect with.
linePointPoint of the line to intersect with.
outIntersectionPlace to store the intersection point, if there is one.
Returns
True if there was an intersection, false if there was not.

Definition at line 86 of file plane3d.h.

89  {
90  T t2 = Normal.dotProduct(lineVect);
91 
92  if (t2 == 0)
93  return false;
94 
95  T t =- (Normal.dotProduct(linePoint) + D) / t2;
96  outIntersection = linePoint + (lineVect * t);
97  return true;
98  }
T D
Distance from origin.
Definition: plane3d.h:231
GLdouble GLdouble t
Definition: SDL_opengl.h:2071
vector3d< T > Normal
Normal vector of the plane.
Definition: plane3d.h:228

◆ getIntersectionWithPlane()

template<class T>
bool irr::core::plane3d< T >::getIntersectionWithPlane ( const plane3d< T > &  other,
vector3d< T > &  outLinePoint,
vector3d< T > &  outLineVect 
) const
inline

Intersects this plane with another.

Parameters
otherOther plane to intersect with.
outLinePointBase point of intersection line.
outLineVectVector of intersection.
Returns
True if there is a intersection, false if not.

Definition at line 173 of file plane3d.h.

176  {
177  const T fn00 = Normal.getLength();
178  const T fn01 = Normal.dotProduct(other.Normal);
179  const T fn11 = other.Normal.getLength();
180  const f64 det = fn00*fn11 - fn01*fn01;
181 
182  if (fabs(det) < ROUNDING_ERROR_f64 )
183  return false;
184 
185  const f64 invdet = 1.0 / det;
186  const f64 fc0 = (fn11*-D + fn01*other.D) * invdet;
187  const f64 fc1 = (fn00*-other.D + fn01*D) * invdet;
188 
189  outLineVect = Normal.crossProduct(other.Normal);
190  outLinePoint = Normal*(T)fc0 + other.Normal*(T)fc1;
191  return true;
192  }
T D
Distance from origin.
Definition: plane3d.h:231
vector3d< T > Normal
Normal vector of the plane.
Definition: plane3d.h:228
double f64
64 bit floating point variable.
Definition: irrTypes.h:112
const f64 ROUNDING_ERROR_f64
Definition: irrMath.h:51

◆ getIntersectionWithPlanes()

template<class T>
bool irr::core::plane3d< T >::getIntersectionWithPlanes ( const plane3d< T > &  o1,
const plane3d< T > &  o2,
vector3d< T > &  outPoint 
) const
inline

Get the intersection point with two other planes if there is one.

Definition at line 195 of file plane3d.h.

197  {
198  vector3d<T> linePoint, lineVect;
199  if (getIntersectionWithPlane(o1, linePoint, lineVect))
200  return o2.getIntersectionWithLine(linePoint, lineVect, outPoint);
201 
202  return false;
203  }
bool getIntersectionWithPlane(const plane3d< T > &other, vector3d< T > &outLinePoint, vector3d< T > &outLineVect) const
Intersects this plane with another.
Definition: plane3d.h:173

◆ getKnownIntersectionWithLine()

template<class T>
f32 irr::core::plane3d< T >::getKnownIntersectionWithLine ( const vector3d< T > &  linePoint1,
const vector3d< T > &  linePoint2 
) const
inline

Get percentage of line between two points where an intersection with this plane happens.

Only useful if known that there is an intersection.

Parameters
linePoint1Point1 of the line to intersect with.
linePoint2Point2 of the line to intersect with.
Returns
Where on a line between two points an intersection with this plane happened. For example, 0.5 is returned if the intersection happened exactly in the middle of the two points.

Definition at line 107 of file plane3d.h.

109  {
110  vector3d<T> vect = linePoint2 - linePoint1;
111  T t2 = (f32)Normal.dotProduct(vect);
112  return (f32)-((Normal.dotProduct(linePoint1) + D) / t2);
113  }
T D
Distance from origin.
Definition: plane3d.h:231
float f32
32 bit floating point variable.
Definition: irrTypes.h:108
vector3d< T > Normal
Normal vector of the plane.
Definition: plane3d.h:228

◆ getMemberPoint()

template<class T>
vector3d<T> irr::core::plane3d< T >::getMemberPoint ( ) const
inline

Gets a member point of the plane.

Definition at line 155 of file plane3d.h.

156  {
157  return Normal * -D;
158  }
T D
Distance from origin.
Definition: plane3d.h:231
vector3d< T > Normal
Normal vector of the plane.
Definition: plane3d.h:228

◆ isFrontFacing()

template<class T>
bool irr::core::plane3d< T >::isFrontFacing ( const vector3d< T > &  lookDirection) const
inline

Test if the triangle would be front or backfacing from any point.

Thus, this method assumes a camera position from which the triangle is definitely visible when looking into the given direction. Note that this only works if the normal is Normalized. Do not use this method with points as it will give wrong results!

Parameters
lookDirectionLook direction.
Returns
True if the plane is front facing and false if it is backfacing.

Definition at line 214 of file plane3d.h.

215  {
216  const f32 d = Normal.dotProduct(lookDirection);
217  return F32_LOWER_EQUAL_0 ( d );
218  }
float f32
32 bit floating point variable.
Definition: irrTypes.h:108
vector3d< T > Normal
Normal vector of the plane.
Definition: plane3d.h:228
#define F32_LOWER_EQUAL_0(n)
Definition: irrMath.h:423

◆ operator!=()

template<class T>
bool irr::core::plane3d< T >::operator!= ( const plane3d< T > &  other) const
inline

Definition at line 54 of file plane3d.h.

54 { return !(*this == other);}

◆ operator==()

template<class T>
bool irr::core::plane3d< T >::operator== ( const plane3d< T > &  other) const
inline

Definition at line 52 of file plane3d.h.

52 { return (equals(D, other.D) && Normal==other.Normal);}
T D
Distance from origin.
Definition: plane3d.h:231
vector3d< T > Normal
Normal vector of the plane.
Definition: plane3d.h:228
bool equals(const T a, const T b, const T tolerance=roundingError< T >())
returns if a equals b, taking possible rounding errors into account
Definition: irrMath.h:246

◆ recalculateD()

template<class T>
void irr::core::plane3d< T >::recalculateD ( const vector3d< T > &  MPoint)
inline

Recalculates the distance from origin by applying a new member point to the plane.

Definition at line 149 of file plane3d.h.

150  {
151  D = - MPoint.dotProduct(Normal);
152  }
T D
Distance from origin.
Definition: plane3d.h:231
vector3d< T > Normal
Normal vector of the plane.
Definition: plane3d.h:228

◆ setPlane() [1/3]

template<class T>
void irr::core::plane3d< T >::setPlane ( const vector3d< T > &  point,
const vector3d< T > &  nvector 
)
inline

Definition at line 58 of file plane3d.h.

59  {
60  Normal = nvector;
61  recalculateD(point);
62  }
vector3d< T > Normal
Normal vector of the plane.
Definition: plane3d.h:228
void recalculateD(const vector3d< T > &MPoint)
Recalculates the distance from origin by applying a new member point to the plane.
Definition: plane3d.h:149

◆ setPlane() [2/3]

template<class T>
void irr::core::plane3d< T >::setPlane ( const vector3d< T > &  nvect,
d 
)
inline

Definition at line 64 of file plane3d.h.

65  {
66  Normal = nvect;
67  D = d;
68  }
T D
Distance from origin.
Definition: plane3d.h:231
vector3d< T > Normal
Normal vector of the plane.
Definition: plane3d.h:228

◆ setPlane() [3/3]

template<class T>
void irr::core::plane3d< T >::setPlane ( const vector3d< T > &  point1,
const vector3d< T > &  point2,
const vector3d< T > &  point3 
)
inline

Definition at line 70 of file plane3d.h.

71  {
72  // creates the plane from 3 memberpoints
73  Normal = (point2 - point1).crossProduct(point3 - point1);
74  Normal.normalize();
75 
76  recalculateD(point1);
77  }
vector3d< T > Normal
Normal vector of the plane.
Definition: plane3d.h:228
void recalculateD(const vector3d< T > &MPoint)
Recalculates the distance from origin by applying a new member point to the plane.
Definition: plane3d.h:149

Member Data Documentation

◆ D

template<class T>
T irr::core::plane3d< T >::D

Distance from origin.

Definition at line 231 of file plane3d.h.

◆ Normal

template<class T>
vector3d<T> irr::core::plane3d< T >::Normal

Normal vector of the plane.

Definition at line 228 of file plane3d.h.


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