g4tools  5.4.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
tools::cubic< T > Class Template Reference

Public Member Functions

 cubic (const vec3< T > &a_p0, const vec3< T > &a_v0, const vec3< T > &a_p1, const vec3< T > &a_v1)
 
 cubic (const T &a_p0_x, const T &a_p0_y, const T &a_p0_z, const T &a_v0_x, const T &a_v0_y, const T &a_v0_z, const T &a_p1_x, const T &a_p1_y, const T &a_p1_z, const T &a_v1_x, const T &a_v1_y, const T &a_v1_z)
 
virtual ~cubic ()
 
 cubic (const cubic &a_from)
 
cubicoperator= (const cubic &a_from)
 
void get_point (unsigned int a_index, unsigned int a_num, vec3< T > &a_p)
 
void get_point (unsigned int a_index, unsigned int a_num, T &a_x, T &a_y, T &a_z)
 

Protected Member Functions

void initialize (const T &a_p0_x, const T &a_p0_y, const T &a_p0_z, const T &a_v0_x, const T &a_v0_y, const T &a_v0_z, const T &a_p1_x, const T &a_p1_y, const T &a_p1_z, const T &a_v1_x, const T &a_v1_y, const T &a_v1_z)
 

Protected Attributes

vec3< T > m_a
 
vec3< T > m_b
 
vec3< T > m_c
 
vec3< T > m_d
 

Detailed Description

template<class T>
class tools::cubic< T >

Definition at line 14 of file geom3.

Constructor & Destructor Documentation

◆ cubic() [1/3]

template<class T >
tools::cubic< T >::cubic ( const vec3< T > &  a_p0,
const vec3< T > &  a_v0,
const vec3< T > &  a_p1,
const vec3< T > &  a_v1 
)
inline

Definition at line 16 of file geom3.

17  {
18  // Construct a cubic given 2 points and their tangents.
19  initialize(a_p0.x(),a_p0.y(),a_p0.z(),
20  a_v0.x(),a_v0.y(),a_v0.z(),
21  a_p1.x(),a_p1.y(),a_p1.z(),
22  a_v1.x(),a_v1.y(),a_v1.z());
23  }

◆ cubic() [2/3]

template<class T >
tools::cubic< T >::cubic ( const T &  a_p0_x,
const T &  a_p0_y,
const T &  a_p0_z,
const T &  a_v0_x,
const T &  a_v0_y,
const T &  a_v0_z,
const T &  a_p1_x,
const T &  a_p1_y,
const T &  a_p1_z,
const T &  a_v1_x,
const T &  a_v1_y,
const T &  a_v1_z 
)
inline

Definition at line 24 of file geom3.

27  {
28  initialize(a_p0_x,a_p0_y,a_p0_z,
29  a_v0_x,a_v0_y,a_v0_z,
30  a_p1_x,a_p1_y,a_p1_z,
31  a_v1_x,a_v1_y,a_v1_z);
32  }

◆ ~cubic()

template<class T >
virtual tools::cubic< T >::~cubic ( )
inlinevirtual

Definition at line 34 of file geom3.

34 {}

◆ cubic() [3/3]

template<class T >
tools::cubic< T >::cubic ( const cubic< T > &  a_from)
inline

Definition at line 36 of file geom3.

37  :m_a(a_from.m_a)
38  ,m_b(a_from.m_b)
39  ,m_c(a_from.m_c)
40  ,m_d(a_from.m_d)
41  {}

Member Function Documentation

◆ get_point() [1/2]

template<class T >
void tools::cubic< T >::get_point ( unsigned int  a_index,
unsigned int  a_num,
T &  a_x,
T &  a_y,
T &  a_z 
)
inline

Definition at line 58 of file geom3.

58  {
59  //a_index = 0 is a_p0
60  //a_index = a_num-1 is a_p1
61  T s = T(a_index)/T(a_num-1);
62  T s2 = s*s;
63  T s3 = s2*s;
64  a_x = m_a.x()*s3 + m_b.x()*s2 + m_c.x()*s + m_d.x();
65  a_y = m_a.y()*s3 + m_b.y()*s2 + m_c.y()*s + m_d.y();
66  a_z = m_a.z()*s3 + m_b.z()*s2 + m_c.z()*s + m_d.z();
67  }

◆ get_point() [2/2]

template<class T >
void tools::cubic< T >::get_point ( unsigned int  a_index,
unsigned int  a_num,
vec3< T > &  a_p 
)
inline

Definition at line 50 of file geom3.

50  {
51  //a_index = 0 is a_p0
52  //a_index = a_num-1 is a_p1
53  T s = T(a_index)/T(a_num-1);
54  T s2 = s*s;
55  T s3 = s2*s;
56  a_p = m_a*s3 + m_b*s2 + m_c*s + m_d;
57  }

◆ initialize()

template<class T >
void tools::cubic< T >::initialize ( const T &  a_p0_x,
const T &  a_p0_y,
const T &  a_p0_z,
const T &  a_v0_x,
const T &  a_v0_y,
const T &  a_v0_z,
const T &  a_p1_x,
const T &  a_p1_y,
const T &  a_p1_z,
const T &  a_v1_x,
const T &  a_v1_y,
const T &  a_v1_z 
)
inlineprotected

Definition at line 69 of file geom3.

72  {
73  // Construct a cubic given 2 points and their tangents.
74 
75  // f(s) = a s**3 + b s**2 + c s + d
76  // f'(s) = 3 a s**2 + 2 b s + c
77 
78  // f(0) = d = p0
79  // f'(0) = c = v0
80 
81  // f(1) = a + b + v0 + p0 = p1
82  // f'(1) = 3 a + 2 b + v0 = v1
83 
84  // f(1) = a + b = p1 - v0 - p0
85  // f'(1) = 3 a + 2 b = v1 - v0
86 
87  // b = 3(p1-v0-p0)-(v1-v0)
88  // a = p1-v0-p0 - b = p1-v0-p0-3(p1-v0-p0)+(v1-v0)
89  // a = -2p1 + v0 + 2p0 + v1
90 
91  T a_x = -2*a_p1_x + a_v0_x + 2*a_p0_x + a_v1_x;
92  T a_y = -2*a_p1_y + a_v0_y + 2*a_p0_y + a_v1_y;
93  T a_z = -2*a_p1_z + a_v0_z + 2*a_p0_z + a_v1_z;
94  m_a.set_value(a_x,a_y,a_z);
95 
96  T b_x = 3*(a_p1_x - a_v0_x - a_p0_x) - (a_v1_x - a_v0_x);
97  T b_y = 3*(a_p1_y - a_v0_y - a_p0_y) - (a_v1_y - a_v0_y);
98  T b_z = 3*(a_p1_z - a_v0_z - a_p0_z) - (a_v1_z - a_v0_z);
99  m_b.set_value(b_x,b_y,b_z);
100 
101  m_c.set_value(a_v0_x,a_v0_y,a_v0_z);
102  m_d.set_value(a_p0_x,a_p0_y,a_p0_z);
103 
104  }

◆ operator=()

template<class T >
cubic& tools::cubic< T >::operator= ( const cubic< T > &  a_from)
inline

Definition at line 42 of file geom3.

42  {
43  m_a = a_from.m_a;
44  m_b = a_from.m_b;
45  m_c = a_from.m_c;
46  m_d = a_from.m_d;
47  return *this;
48  }

Member Data Documentation

◆ m_a

template<class T >
vec3<T> tools::cubic< T >::m_a
protected

Definition at line 107 of file geom3.

◆ m_b

template<class T >
vec3<T> tools::cubic< T >::m_b
protected

Definition at line 108 of file geom3.

◆ m_c

template<class T >
vec3<T> tools::cubic< T >::m_c
protected

Definition at line 109 of file geom3.

◆ m_d

template<class T >
vec3<T> tools::cubic< T >::m_d
protected

Definition at line 110 of file geom3.


The documentation for this class was generated from the following file:
tools::cubic::m_d
vec3< T > m_d
Definition: geom3:110
tools::cubic::m_c
vec3< T > m_c
Definition: geom3:109
tools::cubic::m_a
vec3< T > m_a
Definition: geom3:107
tools::cubic::initialize
void initialize(const T &a_p0_x, const T &a_p0_y, const T &a_p0_z, const T &a_v0_x, const T &a_v0_y, const T &a_v0_z, const T &a_p1_x, const T &a_p1_y, const T &a_p1_z, const T &a_v1_x, const T &a_v1_y, const T &a_v1_z)
Definition: geom3:69
tools::cubic::m_b
vec3< T > m_b
Definition: geom3:108