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 ()=default
 Construct a 3D-vector with x, y, z = 0. More...
 
 VECTOR3 (T x, T y, T z)
 Construct a vector with given components x, y, z. More...
 
template<typename CastingType >
 VECTOR3 (const VECTOR3< CastingType > &aVec)
 Initializes a vector from another specialization. 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
 
VECTOR3< T > & operator*= (T val)
 
VECTOR3< T > & operator/= (T val)
 

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 52 of file vector3.h.

Member Typedef Documentation

◆ coord_type

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

Definition at line 56 of file vector3.h.

◆ extended_type

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

Definition at line 55 of file vector3.h.

Constructor & Destructor Documentation

◆ VECTOR3() [1/3]

template<class T = int>
VECTOR3< T >::VECTOR3 ( )
default

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

◆ VECTOR3() [2/3]

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

Construct a vector with given components x, y, z.

Definition at line 112 of file vector3.h.

112 :
113 x( aX ), y( aY ), z( aZ )
114{
115}
T y
Definition: vector3.h:62
T z
Definition: vector3.h:63
T x
Definition: vector3.h:61

◆ VECTOR3() [3/3]

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

Initializes a vector from another specialization.

Beware of rounding issues.

Definition at line 120 of file vector3.h.

120 :
121 x( aVec.x ), y( aVec.y ), z( aVec.z )
122{
123}

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 127 of file vector3.h.

128{
129 return VECTOR3<T>( ( y * aVector.z ) - ( z * aVector.y ),
130 ( z * aVector.x ) - ( x * aVector.z ),
131 ( x * aVector.y ) - ( y * aVector.x )
132 );
133}
Define a general 3D-vector.
Definition: vector3.h:53

References VECTOR3< T >::x, VECTOR3< T >::y, and VECTOR3< T >::z.

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 137 of file vector3.h.

138{
139 return extended_type{x} * extended_type{aVector.x}
140 + extended_type{y} * extended_type{aVector.y}
141 + extended_type{z} * extended_type{aVector.z};
142}
VECTOR3_TRAITS< T >::extended_type extended_type
Definition: vector3.h:55

References VECTOR3< T >::x, VECTOR3< T >::y, and VECTOR3< T >::z.

◆ EuclideanNorm()

template<class T >
T VECTOR3< T >::EuclideanNorm

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 146 of file vector3.h.

147{
148 return sqrt( (extended_type) x * x + (extended_type) y * y + (extended_type) z * z );
149}

Referenced by PCB_POINT_EDITOR::editArcEndpointKeepTangent().

◆ Normalize()

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

Compute the normalized vector.

Equality operator

Definition at line 153 of file vector3.h.

154{
155 T norm = EuclideanNorm();
156
157 wxCHECK_MSG( norm > T( 0 ), *this, wxT( "Invalid element length 0" ) );
158
159 x /= norm;
160 y /= norm;
161 z /= norm;
162
163 return *this;
164}
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition: vector3.h:146

References EuclideanNorm().

Referenced by DXF_IMPORT_PLUGIN::getArbitraryAxis(), SPICE_VALUE::operator*(), SPICE_VALUE::operator+(), SPICE_VALUE::operator-(), and SPICE_VALUE::operator/().

◆ operator!=()

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

Definition at line 175 of file vector3.h.

176{
177 return ( aVector.x != x ) || ( aVector.y != y ) || ( aVector.z != z );
178}

References VECTOR3< T >::x, VECTOR3< T >::y, and VECTOR3< T >::z.

◆ operator*=()

template<class T >
VECTOR3< T > & VECTOR3< T >::operator*= ( val)

Definition at line 182 of file vector3.h.

183{
184 x = x * aScalar;
185 y = y * aScalar;
186 z = z * aScalar;
187
188 return *this;
189}

◆ operator/=()

template<class T >
VECTOR3< T > & VECTOR3< T >::operator/= ( val)

Definition at line 193 of file vector3.h.

194{
195 x = x / aScalar;
196 y = y / aScalar;
197 z = z / aScalar;
198
199 return *this;
200}

◆ operator==()

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

Not equality operator.

Definition at line 168 of file vector3.h.

169{
170 return ( aVector.x == x ) && ( aVector.y == y ) && ( aVector.z == z );
171}

References VECTOR3< T >::x, VECTOR3< T >::y, and VECTOR3< T >::z.

Member Data Documentation

◆ ECOORD_MAX

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

Definition at line 58 of file vector3.h.

◆ ECOORD_MIN

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

Definition at line 59 of file vector3.h.

◆ x

◆ y

◆ z


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