g4tools  5.4.0
Public Member Functions | Protected Types | Protected Attributes | List of all members
tools::plane< VEC3 > Class Template Reference

Public Member Functions

 plane ()
 
 plane (const VEC3 &a_p0, const VEC3 &a_p1, const VEC3 &a_p2)
 
 plane (const VEC3 &a_normal, const T &a_distance)
 
 plane (const VEC3 &a_normal, const VEC3 &a_point)
 
virtual ~plane ()
 
 plane (const plane &a_from)
 
planeoperator= (const plane &a_from)
 
bool is_valid () const
 
void offset (const T &a_distance)
 
bool intersect (const line< VEC3 > &a_line, VEC3 &a_intersection) const
 
bool is_in_half_space (const VEC3 &a_point) const
 
const VEC3 & normal () const
 
T distance_from_origin () const
 
T distance (const VEC3 &a_point) const
 
void set (const VEC3 &a_normal, const T &a_distance)
 
void set (const VEC3 &a_normal, const VEC3 &a_point)
 
const VEC3 & getNormal () const
 

Protected Types

typedef VEC3::elem_t T
 

Protected Attributes

VEC3 m_normal
 
T m_distance
 

Detailed Description

template<class VEC3>
class tools::plane< VEC3 >

Definition at line 12 of file plane.

Member Typedef Documentation

◆ T

template<class VEC3 >
typedef VEC3::elem_t tools::plane< VEC3 >::T
protected

Definition at line 14 of file plane.

Constructor & Destructor Documentation

◆ plane() [1/5]

template<class VEC3 >
tools::plane< VEC3 >::plane ( )
inline

Definition at line 16 of file plane.

16 {}

◆ plane() [2/5]

template<class VEC3 >
tools::plane< VEC3 >::plane ( const VEC3 &  a_p0,
const VEC3 &  a_p1,
const VEC3 &  a_p2 
)
inline

Definition at line 18 of file plane.

18  {
19  // Construct a plane given 3 points.
20  // Orientation is computed by taking (p1 - p0) x (p2 - p0) and
21  // pointing the normal in that direction.
22 
23  VEC3 P = a_p1;
24  P.subtract(a_p0);
25  VEC3 P2 = a_p2;
26  P2.subtract(a_p0);
27  P.cross(P2,m_normal);
28  if(!m_normal.normalize()) {} //throw
29  m_distance =
30  m_normal.v0() * a_p0.v0() +
31  m_normal.v1() * a_p0.v1() +
32  m_normal.v2() * a_p0.v2();
33  }

◆ plane() [3/5]

template<class VEC3 >
tools::plane< VEC3 >::plane ( const VEC3 &  a_normal,
const T a_distance 
)
inline

Definition at line 35 of file plane.

35  {
36  set(a_normal,a_distance);
37  }

◆ plane() [4/5]

template<class VEC3 >
tools::plane< VEC3 >::plane ( const VEC3 &  a_normal,
const VEC3 &  a_point 
)
inline

Definition at line 39 of file plane.

39  {
40  set(a_normal,a_point);
41  }

◆ ~plane()

template<class VEC3 >
virtual tools::plane< VEC3 >::~plane ( )
inlinevirtual

Definition at line 43 of file plane.

43 {}

◆ plane() [5/5]

template<class VEC3 >
tools::plane< VEC3 >::plane ( const plane< VEC3 > &  a_from)
inline

Definition at line 45 of file plane.

46  :m_normal(a_from.m_normal)
47  ,m_distance(a_from.m_distance)
48  {}

Member Function Documentation

◆ distance()

template<class VEC3 >
T tools::plane< VEC3 >::distance ( const VEC3 &  a_point) const
inline

Definition at line 92 of file plane.

92  {
93  // Return the distance from point to plane. Positive distance means
94  // the point is in the plane's half space.
95  return a_point.dot(m_normal) - m_distance;
96  }

◆ distance_from_origin()

template<class VEC3 >
T tools::plane< VEC3 >::distance_from_origin ( ) const
inline

Definition at line 90 of file plane.

90 {return m_distance;}

◆ getNormal()

template<class VEC3 >
const VEC3& tools::plane< VEC3 >::getNormal ( ) const
inline

Definition at line 116 of file plane.

116 {return m_normal;}

◆ intersect()

template<class VEC3 >
bool tools::plane< VEC3 >::intersect ( const line< VEC3 > &  a_line,
VEC3 &  a_intersection 
) const
inline

Definition at line 63 of file plane.

63  {
64  // Intersect line and plane, returning true if there is an intersection
65  // false if line is parallel to plane
66  const VEC3& pos = a_line.position();
67  const VEC3& dir = a_line.direction();
68  T d = m_normal.dot(dir);
69  if(d==T()) return false;
70  T t = (m_distance - m_normal.dot(pos))/d;
71  a_intersection = dir;
72  a_intersection.multiply(t);
73  a_intersection.add(pos);
74  //a_intersection = pos + t * dir;
75  return true;
76  }

◆ is_in_half_space()

template<class VEC3 >
bool tools::plane< VEC3 >::is_in_half_space ( const VEC3 &  a_point) const
inline

Definition at line 78 of file plane.

78  {
79  // Returns true if the given point is within the half-space
80  // defined by the plane
81  //vec pos = m_normal * m_distance;
82  VEC3 pos = m_normal;
83  pos.multiply(-m_distance);
84  pos.add(a_point);
85  return (m_normal.dot(pos) >= T() ? true : false);
86  }

◆ is_valid()

template<class VEC3 >
bool tools::plane< VEC3 >::is_valid ( ) const
inline

Definition at line 56 of file plane.

56 {return m_normal.length()?true:false;}

◆ normal()

template<class VEC3 >
const VEC3& tools::plane< VEC3 >::normal ( ) const
inline

Definition at line 88 of file plane.

88 {return m_normal;}

◆ offset()

template<class VEC3 >
void tools::plane< VEC3 >::offset ( const T a_distance)
inline

Definition at line 58 of file plane.

58  {
59  // Offset a plane by a given distance.
60  m_distance += a_distance;
61  }

◆ operator=()

template<class VEC3 >
plane& tools::plane< VEC3 >::operator= ( const plane< VEC3 > &  a_from)
inline

Definition at line 49 of file plane.

49  {
50  m_normal = a_from.m_normal;
51  m_distance = a_from.m_distance;
52  return *this;
53  }

◆ set() [1/2]

template<class VEC3 >
void tools::plane< VEC3 >::set ( const VEC3 &  a_normal,
const T a_distance 
)
inline

Definition at line 98 of file plane.

98  {
99  m_normal = a_normal;
100  if(!m_normal.normalize()) {} //throw
101  m_distance = a_distance;
102  }

◆ set() [2/2]

template<class VEC3 >
void tools::plane< VEC3 >::set ( const VEC3 &  a_normal,
const VEC3 &  a_point 
)
inline

Definition at line 104 of file plane.

104  {
105  // Construct a plane given normal and a point to pass through
106  // Orientation is given by the normal vector n.
107  m_normal = a_normal;
108  if(!m_normal.normalize()) {} //throw
109  m_distance =
110  m_normal.v0() * a_point.v0() +
111  m_normal.v1() * a_point.v1() +
112  m_normal.v2() * a_point.v2();
113  }

Member Data Documentation

◆ m_distance

template<class VEC3 >
T tools::plane< VEC3 >::m_distance
protected

Definition at line 122 of file plane.

◆ m_normal

template<class VEC3 >
VEC3 tools::plane< VEC3 >::m_normal
protected

Definition at line 121 of file plane.


The documentation for this class was generated from the following file:
tools::plane::set
void set(const VEC3 &a_normal, const T &a_distance)
Definition: plane:98
tools::plane::T
VEC3::elem_t T
Definition: plane:14
tools::plane::m_distance
T m_distance
Definition: plane:122
tools::plane::m_normal
VEC3 m_normal
Definition: plane:121