SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLPlane Class Reference

Defines a plane in 3D space with the equation ax + by + cy + d = 0. More...

#include <SLPlane.h>

Public Member Functions

 SLPlane (const SLVec3f &v1, const SLVec3f &v2, const SLVec3f &v3)
 
 SLPlane ()
 
 ~SLPlane ()
 
void setPoints (const SLVec3f &v1, const SLVec3f &v2, const SLVec3f &v3)
 
void setNormalAndPoint (const SLVec3f &N, const SLVec3f &P)
 
void setCoefficients (const SLfloat A, const SLfloat B, const SLfloat C, const SLfloat D)
 
SLfloat distToPoint (const SLVec3f &p)
 Returns distance between a point P and the plane. More...
 
void print (const char *name)
 

Public Attributes

SLVec3f N
 plane normal More...
 
SLfloat d
 d = -(ax+by+cy) = -normal.dot(point) More...
 

Detailed Description

Defines a plane in 3D space with the equation ax + by + cy + d = 0.

SLPlane defines a plane in 3D space with the equation ax + by + cy + d = 0 where [a,b,c] is the plane normal and d is the distance from [0,0,0]. The class is used to define the 6 planes of the view frustum.

Definition at line 24 of file SLPlane.h.

Constructor & Destructor Documentation

◆ SLPlane() [1/2]

SLPlane::SLPlane ( const SLVec3f v0,
const SLVec3f v1,
const SLVec3f v2 
)

SLPlane::SLPlane ctor with 3 points

Definition at line 16 of file SLPlane.cpp.

19 {
20  setPoints(v0, v1, v2);
21 }
void setPoints(const SLVec3f &v1, const SLVec3f &v2, const SLVec3f &v3)
Definition: SLPlane.cpp:26

◆ SLPlane() [2/2]

SLPlane::SLPlane ( )
inline

Definition at line 30 of file SLPlane.h.

31  {
32  N.set(0, 0, 1);
33  d = 0.0f;
34  }
SLfloat d
d = -(ax+by+cy) = -normal.dot(point)
Definition: SLPlane.h:38
SLVec3f N
plane normal
Definition: SLPlane.h:37
void set(const T X, const T Y, const T Z)
Definition: SLVec3.h:59

◆ ~SLPlane()

SLPlane::~SLPlane ( )
inline

Definition at line 35 of file SLPlane.h.

35 { ; }

Member Function Documentation

◆ distToPoint()

SLfloat SLPlane::distToPoint ( const SLVec3f p)
inline

Returns distance between a point P and the plane.

Definition at line 51 of file SLPlane.h.

51 { return (d + N.dot(p)); }
T dot(const SLVec3 &v) const
Definition: SLVec3.h:117

◆ print()

void SLPlane::print ( const char *  name)

SLPlane::print prints the normal and the coefficent d

Definition at line 71 of file SLPlane.cpp.

72 {
73  SLMATH_LOG("Plane(%s: a=%4.3f, b=%4.3f, c=%4.3f)",
74  name,
75  N.x,
76  N.y,
77  N.z);
78 }
#define SLMATH_LOG(...)
Definition: SLMath.h:70
T y
Definition: SLVec3.h:43
T x
Definition: SLVec3.h:43
T z
Definition: SLVec3.h:43

◆ setCoefficients()

void SLPlane::setCoefficients ( const SLfloat  A,
const SLfloat  B,
const SLfloat  C,
const SLfloat  D 
)

SLPlane::setByCoefficients defines the plane by the coefficient A,B,C & D

Definition at line 50 of file SLPlane.cpp.

54 {
55  // set the normal vector
56  N.set(A, B, C);
57 
58  //compute the lenght of the vector
59  SLfloat len = N.length();
60 
61  // normalize the vector
62  N.set(N.x / len, N.y / len, N.z / len);
63 
64  // and divide d by th length as well
65  d = D / len;
66 }
float SLfloat
Definition: SL.h:173
T length() const
Definition: SLVec3.h:122

◆ setNormalAndPoint()

void SLPlane::setNormalAndPoint ( const SLVec3f normal,
const SLVec3f P 
)

SLPlane::setByNormalAndPoint defines the plane by a normal N and a point P

Definition at line 40 of file SLPlane.cpp.

41 {
42  N.set(normal);
43  N.normalize();
44  d = -N.dot(P);
45 }
SLVec3 & normalize()
Definition: SLVec3.h:124

◆ setPoints()

void SLPlane::setPoints ( const SLVec3f v0,
const SLVec3f v1,
const SLVec3f v2 
)

SLPlane::setFromPoints set the plane from 3 points

Definition at line 26 of file SLPlane.cpp.

29 {
30  SLVec3f edge1(v1 - v0);
31  SLVec3f edge2(v2 - v0);
32  N.cross(edge1, edge2);
33  N.normalize();
34  d = -N.dot(v0);
35 }
void cross(const SLVec3 &a, const SLVec3 &b)
Definition: SLVec3.h:118

Member Data Documentation

◆ d

SLfloat SLPlane::d

d = -(ax+by+cy) = -normal.dot(point)

Definition at line 38 of file SLPlane.h.

◆ N

SLVec3f SLPlane::N

plane normal

Definition at line 37 of file SLPlane.h.


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