NGL  6.5
The NCCA Graphics Library
Plane.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 Jon Macey
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received m_a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 #include "Plane.h"
18 //----------------------------------------------------------------------------------------------------------------------
21 //----------------------------------------------------------------------------------------------------------------------
22 namespace ngl
23 {
24 
25 //----------------------------------------------------------------------------------------------------------------------
26 Plane::Plane() noexcept
27 {
28 
29 }
30 //----------------------------------------------------------------------------------------------------------------------
31 Plane::Plane( const Vec3 &_v1, const Vec3 &_v2, const Vec3 &_v3) noexcept
32 {
33  setPoints(_v1,_v2,_v3);
34 }
35 
36 //----------------------------------------------------------------------------------------------------------------------
37 Plane::~Plane() noexcept
38 {
39 
40 }
41 //----------------------------------------------------------------------------------------------------------------------
42 void Plane::setPoints(const Vec3 &_v1, const Vec3 &_v2, const Vec3 &_v3) noexcept
43 {
44  Vec3 aux1, aux2;
45 
46  aux1 = _v1 - _v2;
47  aux2 = _v3 - _v2;
48  m_normal = aux2.cross(aux1);
50  m_point=_v2;
51  m_d = -(m_normal.inner(m_point));
52 }
53 //----------------------------------------------------------------------------------------------------------------------
54 void Plane::setNormalPoint( const Vec3 &_normal, const Vec3 &_point) noexcept
55 {
56  m_point=_point;
57  m_normal=_normal;
59  m_d = -(m_normal.inner(m_point));
60 }
61 //----------------------------------------------------------------------------------------------------------------------
62 void Plane::setFloats(Real _a,Real _b, Real _c, Real _d) noexcept
63 {
64  // set the normal vector
65  m_normal.set(_a,_b,_c);
66  //compute the lenght of the vector
67  Real l = m_normal.length();
68  // normalize the vector
70  // and divide d by th length as well
71  m_d = _d/l;
72 }
73 
74 //----------------------------------------------------------------------------------------------------------------------
75 Real Plane::distance( const Vec3 &_p) const noexcept
76 {
77  return (m_d + m_normal.inner(_p));
78 }
79 
80 } // end of ngl namespace
void setPoints(const Vec3 &_v1, const Vec3 &_v2, const Vec3 &_v3) noexcept
set the plane from 3 points
Definition: Plane.cpp:42
Real m_d
the co-efficient of the plane
Definition: Plane.h:119
Vec3 m_normal
the normal of the plane
Definition: Plane.h:111
~Plane() noexcept
dtor (not used)
Definition: Plane.cpp:37
Real inner(const Vec3 &_v) const noexcept
calculate the inner product of this vector and vector passed in
Definition: Vec3.cpp:216
simple Vec3 encapsulates a 3 float object like glsl vec3 but not maths use the Vec3 class for maths a...
Definition: Vec3.h:51
implementation files for RibExport class
Definition: AABB.cpp:22
GLdouble l
Definition: glew.h:9162
a simple mathmatical representation of a plane
PRECISION Real
create a variable called Real which is the main data type we use (GLfloat for most cases) ...
Definition: Types.h:127
void setNormalPoint(const Vec3 &_normal, const Vec3 &_point) noexcept
set the plane from a normal and a point
Definition: Plane.cpp:54
void set(Real _x, Real _y, Real _z) noexcept
sets the Vec3 component from 3 values
Definition: Vec3.cpp:33
void setFloats(Real _a, Real _b, Real _c, Real _d) noexcept
set the plane from the co-efficients
Definition: Plane.cpp:62
Real length() const noexcept
returns the length of the vector
Definition: Vec3.cpp:233
Real distance(const Vec3 &_p) const noexcept
get the distance from the point _p to the plane
Definition: Plane.cpp:75
Vec3 m_point
the point position of the normal / plane
Definition: Plane.h:115
void normalize() noexcept
Normalize the vector using .
Definition: Vec3.cpp:206
void cross(const Vec3 &_v1, const Vec3 &_v2) noexcept
set the Vec3 as the cross product from 2 other Vec3
Definition: Vec3.cpp:187
Plane() noexcept
default ctor
Definition: Plane.cpp:26