SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLPlane.cpp
Go to the documentation of this file.
1 /**
2  * \file math/SLPlane.cpp
3  * \brief Implementation of the the SLPlane class
4  * \date July 2014
5  * \authors Marcus Hudritsch
6  * \copyright http://opensource.org/licenses/GPL-3.0
7  * \remarks Please use clangformat to format the code. See more code style on
8  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
9 */
10 
11 #include <SLPlane.h>
12 //-----------------------------------------------------------------------------
13 /*!
14 SLPlane::SLPlane ctor with 3 points
15 */
17  const SLVec3f& v1,
18  const SLVec3f& v2)
19 {
20  setPoints(v0, v1, v2);
21 }
22 //-----------------------------------------------------------------------------
23 /*!
24 SLPlane::setFromPoints set the plane from 3 points
25 */
26 void SLPlane::setPoints(const SLVec3f& v0,
27  const SLVec3f& v1,
28  const SLVec3f& v2)
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 }
36 //-----------------------------------------------------------------------------
37 /*!
38 SLPlane::setByNormalAndPoint defines the plane by a normal N and a point P
39 */
40 void SLPlane::setNormalAndPoint(const SLVec3f& normal, const SLVec3f& P)
41 {
42  N.set(normal);
43  N.normalize();
44  d = -N.dot(P);
45 }
46 //-----------------------------------------------------------------------------
47 /*!
48 SLPlane::setByCoefficients defines the plane by the coefficient A,B,C & D
49 */
51  const SLfloat B,
52  const SLfloat C,
53  SLfloat D)
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 }
67 //-----------------------------------------------------------------------------
68 /*!
69 SLPlane::print prints the normal and the coefficent d
70 */
71 void SLPlane::print(const char* name)
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 }
79 //-----------------------------------------------------------------------------
float SLfloat
Definition: SL.h:173
#define SLMATH_LOG(...)
Definition: SLMath.h:70
void setCoefficients(const SLfloat A, const SLfloat B, const SLfloat C, const SLfloat D)
Definition: SLPlane.cpp:50
SLfloat d
d = -(ax+by+cy) = -normal.dot(point)
Definition: SLPlane.h:38
SLPlane()
Definition: SLPlane.h:30
void setPoints(const SLVec3f &v1, const SLVec3f &v2, const SLVec3f &v3)
Definition: SLPlane.cpp:26
void print(const char *name)
Definition: SLPlane.cpp:71
SLVec3f N
plane normal
Definition: SLPlane.h:37
void setNormalAndPoint(const SLVec3f &N, const SLVec3f &P)
Definition: SLPlane.cpp:40
T y
Definition: SLVec3.h:43
void cross(const SLVec3 &a, const SLVec3 &b)
Definition: SLVec3.h:118
T x
Definition: SLVec3.h:43
SLVec3 & normalize()
Definition: SLVec3.h:124
T length() const
Definition: SLVec3.h:122
void set(const T X, const T Y, const T Z)
Definition: SLVec3.h:59
T dot(const SLVec3 &v) const
Definition: SLVec3.h:117
T z
Definition: SLVec3.h:43