KiCad PCB EDA Suite
VECTOR3< T > Class Template Reference

Define a general 3D-vector. More...

#include <vector3.h>

Public Types

typedef VECTOR3_TRAITS< T >::extended_type extended_type
 
typedef T coord_type
 

Public Member Functions

 VECTOR3 ()
 Construct a 3D-vector with x, y = 0. More...
 
 VECTOR3 (T x, T y, T z)
 Construct a vector with given components x, y. More...
 
template<typename CastingType >
 VECTOR3 (const VECTOR3< CastingType > &aVec)
 Initializes a vector from another specialization. More...
 
 VECTOR3 (const VECTOR3< T > &aVec)
 Copy a vector. More...
 
VECTOR3< T > Cross (const VECTOR3< T > &aVector) const
 Compute cross product of self with aVector. More...
 
VECTOR3< T >::extended_type Dot (const VECTOR3< T > &aVector) const
 Compute the dot product of self with aVector. More...
 
EuclideanNorm () const
 Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2). More...
 
VECTOR3< T > Normalize ()
 Compute the normalized vector. More...
 
bool operator== (const VECTOR3< T > &aVector) const
 Not equality operator. More...
 
bool operator!= (const VECTOR3< T > &aVector) const
 

Public Attributes

x
 
y
 
z
 

Static Public Attributes

static constexpr extended_type ECOORD_MAX = std::numeric_limits<extended_type>::max()
 
static constexpr extended_type ECOORD_MIN = std::numeric_limits<extended_type>::min()
 

Detailed Description

template<class T = int>
class VECTOR3< T >

Define a general 3D-vector.

This class uses templates to be universal. Several operators are provided to help easy implementing of linear algebra equations.

Definition at line 49 of file vector3.h.

Member Typedef Documentation

◆ coord_type

template<class T = int>
typedef T VECTOR3< T >::coord_type

Definition at line 53 of file vector3.h.

◆ extended_type

template<class T = int>
typedef VECTOR3_TRAITS<T>::extended_type VECTOR3< T >::extended_type

Definition at line 52 of file vector3.h.

Constructor & Destructor Documentation

◆ VECTOR3() [1/4]

template<class T >
VECTOR3< T >::VECTOR3 ( )

Construct a 3D-vector with x, y = 0.

Definition at line 117 of file vector3.h.

118 {
119  x = y = z = 0.0;
120 }
T z
Definition: vector3.h:58
T x
Definition: vector3.h:58
T y
Definition: vector3.h:58

◆ VECTOR3() [2/4]

template<class T>
VECTOR3< T >::VECTOR3 ( x,
y,
z 
)

Construct a vector with given components x, y.

Definition at line 124 of file vector3.h.

125 {
126  x = aX;
127  y = aY;
128  z = aZ;
129 }
T z
Definition: vector3.h:58
T x
Definition: vector3.h:58
T y
Definition: vector3.h:58

◆ VECTOR3() [3/4]

template<class T = int>
template<typename CastingType >
VECTOR3< T >::VECTOR3 ( const VECTOR3< CastingType > &  aVec)
inline

Initializes a vector from another specialization.

Beware of rounding issues.

Definition at line 69 of file vector3.h.

70  {
71  x = (T) aVec.x;
72  y = (T) aVec.y;
73  z = (T) aVec.z;
74  }
T z
Definition: vector3.h:58
T x
Definition: vector3.h:58
T y
Definition: vector3.h:58

◆ VECTOR3() [4/4]

template<class T = int>
VECTOR3< T >::VECTOR3 ( const VECTOR3< T > &  aVec)
inline

Copy a vector.

Definition at line 77 of file vector3.h.

78  {
79  x = aVec.x;
80  y = aVec.y;
81  z = aVec.z;
82  }
T z
Definition: vector3.h:58
T x
Definition: vector3.h:58
T y
Definition: vector3.h:58

Member Function Documentation

◆ Cross()

template<class T>
VECTOR3< T > VECTOR3< T >::Cross ( const VECTOR3< T > &  aVector) const

Compute cross product of self with aVector.

Definition at line 133 of file vector3.h.

134 {
135  return VECTOR3<T>( ( y * aVector.z ) - ( z * aVector.y ),
136  ( z * aVector.x ) - ( x * aVector.z ),
137  ( x * aVector.y ) - ( y * aVector.x )
138  );
139 }
T z
Definition: vector3.h:58
Define a general 3D-vector.
Definition: vector3.h:49
T x
Definition: vector3.h:58
T y
Definition: vector3.h:58

Referenced by DXF_IMPORT_PLUGIN::getArbitraryAxis().

◆ Dot()

template<class T>
VECTOR3< T >::extended_type VECTOR3< T >::Dot ( const VECTOR3< T > &  aVector) const

Compute the dot product of self with aVector.

Definition at line 143 of file vector3.h.

144 {
145  return extended_type{x} * extended_type{aVector.x}
146  + extended_type{y} * extended_type{aVector.y}
147  + extended_type{z} * extended_type{aVector.z};
148 }
T z
Definition: vector3.h:58
VECTOR3_TRAITS< T >::extended_type extended_type
Definition: vector3.h:52
T x
Definition: vector3.h:58
T y
Definition: vector3.h:58

◆ EuclideanNorm()

template<class T >
T VECTOR3< T >::EuclideanNorm ( ) const

Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).

It is used to calculate the length of the vector.

Returns
Scalar, the euclidean norm

Definition at line 152 of file vector3.h.

153 {
154  return sqrt( (extended_type) x * x + (extended_type) y * y + (extended_type) z * z );
155 }
T z
Definition: vector3.h:58
VECTOR3_TRAITS< T >::extended_type extended_type
Definition: vector3.h:52
T x
Definition: vector3.h:58
T y
Definition: vector3.h:58

◆ Normalize()

template<class T >
VECTOR3< T > VECTOR3< T >::Normalize ( )

Compute the normalized vector.

Equality operator

Definition at line 159 of file vector3.h.

160 {
161  T norm = EuclideanNorm();
162  x /= norm;
163  y /= norm;
164  z /= norm;
165 
166  return *this;
167 }
T z
Definition: vector3.h:58
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition: vector3.h:152
T x
Definition: vector3.h:58
T y
Definition: vector3.h:58

Referenced by DXF_IMPORT_PLUGIN::getArbitraryAxis().

◆ operator!=()

template<class T>
bool VECTOR3< T >::operator!= ( const VECTOR3< T > &  aVector) const

Definition at line 178 of file vector3.h.

179 {
180  return ( aVector.x != x ) || ( aVector.y != y ) || ( aVector.z != z );
181 }
T z
Definition: vector3.h:58
T x
Definition: vector3.h:58
T y
Definition: vector3.h:58

◆ operator==()

template<class T>
bool VECTOR3< T >::operator== ( const VECTOR3< T > &  aVector) const

Not equality operator.

Definition at line 171 of file vector3.h.

172 {
173  return ( aVector.x == x ) && ( aVector.y == y ) && ( aVector.z == z );
174 }
T z
Definition: vector3.h:58
T x
Definition: vector3.h:58
T y
Definition: vector3.h:58

Member Data Documentation

◆ ECOORD_MAX

template<class T = int>
constexpr extended_type VECTOR3< T >::ECOORD_MAX = std::numeric_limits<extended_type>::max()
static

Definition at line 55 of file vector3.h.

◆ ECOORD_MIN

template<class T = int>
constexpr extended_type VECTOR3< T >::ECOORD_MIN = std::numeric_limits<extended_type>::min()
static

Definition at line 56 of file vector3.h.

◆ x

◆ y

◆ z


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