KiCad PCB EDA Suite
MATRIX3x3< T > Class Template Reference

MATRIX3x3 describes a general 3x3 matrix. More...

#include <matrix3x3.h>

Public Member Functions

 MATRIX3x3 ()
 Initialize all matrix members to zero. More...
 
 MATRIX3x3 (VECTOR3< T > a1, VECTOR3< T > a2, VECTOR3< T > a3)
 Initialize with 3 vectors. More...
 
 MATRIX3x3 (T a00, T a01, T a02, T a10, T a11, T a12, T a20, T a21, T a22)
 Initialize with given matrix members. More...
 
void SetIdentity ()
 Set the matrix to the identity matrix. More...
 
void SetTranslation (VECTOR2< T > aTranslation)
 Set the translation components of the matrix. More...
 
VECTOR2< T > GetTranslation () const
 Get the translation components of the matrix. More...
 
void SetRotation (T aAngle)
 Set the rotation components of the matrix. More...
 
void SetScale (VECTOR2< T > aScale)
 Set the scale components of the matrix. More...
 
VECTOR2< T > GetScale () const
 Get the scale components of the matrix. More...
 
Determinant () const
 Compute the determinant of the matrix. More...
 
MATRIX3x3 Inverse () const
 Determine the inverse of the matrix. More...
 
MATRIX3x3 Transpose () const
 Get the transpose of the matrix. More...
 
bool operator== (const MATRIX3x3< T > &aOtherMatrix) const
 Not equality operator. More...
 
bool operator!= (const MATRIX3x3< T > &aOtherMatrix) const
 

Public Attributes

m_data [3][3]
 

Friends

std::ostream & operator (std::ostream &aStream, const MATRIX3x3< T > &aMatrix)
 Output to a stream. More...
 

Detailed Description

template<class T>
class MATRIX3x3< T >

MATRIX3x3 describes a general 3x3 matrix.

Any linear transformation in 2D can be represented by a homogeneous 3x3 transformation matrix. Given a vector x, the linear transformation with the transformation matrix M is given as

x' = M * x

To represent an affine transformation, homogeneous coordinates have to be used. That means the 2D-vector (x, y) has to be extended to a 3D-vector by a third component (x, y, 1).

Transformations can be easily combined by matrix multiplication.

A * (B * x ) = (A * B) * x ( A, B: transformation matrices, x: vector )

This class was implemented using templates, so flexible type combinations are possible.

Definition at line 62 of file matrix3x3.h.

Constructor & Destructor Documentation

◆ MATRIX3x3() [1/3]

template<class T >
MATRIX3x3< T >::MATRIX3x3

Initialize all matrix members to zero.

Definition at line 193 of file matrix3x3.h.

194{
195 for( int j = 0; j < 3; j++ )
196 {
197 for( int i = 0; i < 3; i++ )
198 {
199 m_data[i][j] = 0.0;
200 }
201 }
202}
T m_data[3][3]
Definition: matrix3x3.h:65

◆ MATRIX3x3() [2/3]

template<class T >
MATRIX3x3< T >::MATRIX3x3 ( VECTOR3< T >  a1,
VECTOR3< T >  a2,
VECTOR3< T >  a3 
)

Initialize with 3 vectors.

Definition at line 206 of file matrix3x3.h.

207{
208 m_data[0][0] = a1.x;
209 m_data[0][1] = a1.y;
210 m_data[0][2] = a1.z;
211
212 m_data[1][0] = a2.x;
213 m_data[1][1] = a2.y;
214 m_data[1][2] = a2.z;
215
216 m_data[2][0] = a3.x;
217 m_data[2][1] = a3.y;
218 m_data[2][2] = a3.z;
219}
T y
Definition: vector3.h:62
T z
Definition: vector3.h:63
T x
Definition: vector3.h:61

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

◆ MATRIX3x3() [3/3]

template<class T >
MATRIX3x3< T >::MATRIX3x3 ( a00,
a01,
a02,
a10,
a11,
a12,
a20,
a21,
a22 
)

Initialize with given matrix members.

Parameters
a00is the component [0,0].
a01is the component [0,1].
a02is the component [0,2].
a10is the component [1,0].
a11is the component [1,1].
a12is the component [1,2].
a20is the component [2,0].
a21is the component [2,1].
a22is the component [2,2].

Definition at line 223 of file matrix3x3.h.

224{
225 m_data[0][0] = a00;
226 m_data[0][1] = a01;
227 m_data[0][2] = a02;
228
229 m_data[1][0] = a10;
230 m_data[1][1] = a11;
231 m_data[1][2] = a12;
232
233 m_data[2][0] = a20;
234 m_data[2][1] = a21;
235 m_data[2][2] = a22;
236}

Member Function Documentation

◆ Determinant()

template<class T >
T MATRIX3x3< T >::Determinant

Compute the determinant of the matrix.

Returns
the determinant value.

Definition at line 351 of file matrix3x3.h.

352{
353 return m_data[0][0] * ( m_data[1][1] * m_data[2][2] - m_data[1][2] * m_data[2][1] )
354 - m_data[0][1] * ( m_data[1][0] * m_data[2][2] - m_data[1][2] * m_data[2][0] )
355 + m_data[0][2] * ( m_data[1][0] * m_data[2][1] - m_data[1][1] * m_data[2][0] );
356}

◆ GetScale()

template<class T >
VECTOR2< T > MATRIX3x3< T >::GetScale

Get the scale components of the matrix.

Returns
the scale factors, specified as 2D-vector.

Definition at line 295 of file matrix3x3.h.

296{
297 VECTOR2<T> result( m_data[0][0], m_data[1][1] );
298
299 return result;
300}
Define a general 2D-vector/point.
Definition: vector2d.h:70

Referenced by KIGFX::PCB_PAINTER::draw(), KIGFX::SCH_PAINTER::getShadowWidth(), KIGFX::GAL::GetVisibleWorldExtents(), KIGFX::OPENGL_GAL::getWorldPixelSize(), KIGFX::VIEW::ToScreen(), and KIGFX::VIEW::ToWorld().

◆ GetTranslation()

template<class T >
VECTOR2< T > MATRIX3x3< T >::GetTranslation

Get the translation components of the matrix.

Returns
is the translation (2D-vector).

Definition at line 264 of file matrix3x3.h.

265{
266 VECTOR2<T> result;
267 result.x = m_data[0][2];
268 result.y = m_data[1][2];
269
270 return result;
271}

References VECTOR2< T >::x, and VECTOR2< T >::y.

◆ Inverse()

template<class T >
MATRIX3x3< T > MATRIX3x3< T >::Inverse

Determine the inverse of the matrix.

The inverse of a transformation matrix can be used to revert a transformation.

x = Minv * ( M * x ) ( M: transformation matrix, Minv: inverse transformation matrix, x: vector)

Returns
the inverse matrix.

Definition at line 384 of file matrix3x3.h.

385{
386 MATRIX3x3<T> result;
387
388 result.m_data[0][0] = m_data[1][1] * m_data[2][2] - m_data[2][1] * m_data[1][2];
389 result.m_data[0][1] = m_data[0][2] * m_data[2][1] - m_data[2][2] * m_data[0][1];
390 result.m_data[0][2] = m_data[0][1] * m_data[1][2] - m_data[1][1] * m_data[0][2];
391
392 result.m_data[1][0] = m_data[1][2] * m_data[2][0] - m_data[2][2] * m_data[1][0];
393 result.m_data[1][1] = m_data[0][0] * m_data[2][2] - m_data[2][0] * m_data[0][2];
394 result.m_data[1][2] = m_data[0][2] * m_data[1][0] - m_data[1][2] * m_data[0][0];
395
396 result.m_data[2][0] = m_data[1][0] * m_data[2][1] - m_data[2][0] * m_data[1][1];
397 result.m_data[2][1] = m_data[0][1] * m_data[2][0] - m_data[2][1] * m_data[0][0];
398 result.m_data[2][2] = m_data[0][0] * m_data[1][1] - m_data[1][0] * m_data[0][1];
399
400 return result * ( 1.0 / Determinant() );
401}
MATRIX3x3 describes a general 3x3 matrix.
Definition: matrix3x3.h:63
T Determinant() const
Compute the determinant of the matrix.
Definition: matrix3x3.h:351

References MATRIX3x3< T >::m_data.

Referenced by KIGFX::GAL::ComputeWorldScreenMatrix(), and KIGFX::CAIRO_PRINT_GAL::ComputeWorldScreenMatrix().

◆ operator!=()

template<class T >
bool MATRIX3x3< T >::operator!= ( const MATRIX3x3< T > &  aOtherMatrix) const

Definition at line 458 of file matrix3x3.h.

459{
460 return aOtherMatrix.m_data[0][0] != m_data[0][0] ||
461 aOtherMatrix.m_data[0][1] != m_data[0][1] ||
462 aOtherMatrix.m_data[0][2] != m_data[0][2] ||
463 aOtherMatrix.m_data[1][0] != m_data[1][0] ||
464 aOtherMatrix.m_data[1][1] != m_data[1][1] ||
465 aOtherMatrix.m_data[1][2] != m_data[1][2] ||
466 aOtherMatrix.m_data[2][0] != m_data[2][0] ||
467 aOtherMatrix.m_data[2][1] != m_data[2][1] ||
468 aOtherMatrix.m_data[2][2] != m_data[2][2];
469}

References MATRIX3x3< T >::m_data.

◆ operator==()

template<class T >
bool MATRIX3x3< T >::operator== ( const MATRIX3x3< T > &  aOtherMatrix) const

Not equality operator.

Definition at line 443 of file matrix3x3.h.

444{
445 return aOtherMatrix.m_data[0][0] == m_data[0][0] &&
446 aOtherMatrix.m_data[0][1] == m_data[0][1] &&
447 aOtherMatrix.m_data[0][2] == m_data[0][2] &&
448 aOtherMatrix.m_data[1][0] == m_data[1][0] &&
449 aOtherMatrix.m_data[1][1] == m_data[1][1] &&
450 aOtherMatrix.m_data[1][2] == m_data[1][2] &&
451 aOtherMatrix.m_data[2][0] == m_data[2][0] &&
452 aOtherMatrix.m_data[2][1] == m_data[2][1] &&
453 aOtherMatrix.m_data[2][2] == m_data[2][2];
454}

References MATRIX3x3< T >::m_data.

◆ SetIdentity()

template<class T >
void MATRIX3x3< T >::SetIdentity ( void  )

Set the matrix to the identity matrix.

The diagonal components of the matrix are set to 1.

Definition at line 240 of file matrix3x3.h.

241{
242 for( int j = 0; j < 3; j++ )
243 {
244 for( int i = 0; i < 3; i++ )
245 {
246 if( i == j )
247 m_data[i][j] = 1.0;
248 else
249 m_data[i][j] = 0.0;
250 }
251 }
252}

Referenced by KIGFX::GAL::ComputeWorldScreenMatrix(), and KIGFX::CAIRO_PRINT_GAL::ComputeWorldScreenMatrix().

◆ SetRotation()

template<class T >
void MATRIX3x3< T >::SetRotation ( aAngle)

Set the rotation components of the matrix.

The angle needs to have a positive value for an anti-clockwise rotation.

Parameters
aAngleis the rotation angle in [rad].

Definition at line 275 of file matrix3x3.h.

276{
277 T cosValue = cos( aAngle );
278 T sinValue = sin( aAngle );
279 m_data[0][0] = cosValue;
280 m_data[0][1] = -sinValue;
281 m_data[1][0] = sinValue;
282 m_data[1][1] = cosValue;
283}

Referenced by DXF_IMPORT_PLUGIN::addInsert(), KIGFX::GAL::ComputeWorldScreenMatrix(), and KIGFX::CAIRO_PRINT_GAL::ComputeWorldScreenMatrix().

◆ SetScale()

template<class T >
void MATRIX3x3< T >::SetScale ( VECTOR2< T >  aScale)

Set the scale components of the matrix.

Parameters
aScalecontains the scale factors, specified as 2D-vector.

Definition at line 287 of file matrix3x3.h.

288{
289 m_data[0][0] = aScale.x;
290 m_data[1][1] = aScale.y;
291}

References VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by KIGFX::GAL::ComputeWorldScreenMatrix(), and KIGFX::CAIRO_PRINT_GAL::ComputeWorldScreenMatrix().

◆ SetTranslation()

template<class T >
void MATRIX3x3< T >::SetTranslation ( VECTOR2< T >  aTranslation)

Set the translation components of the matrix.

Parameters
aTranslationis the translation, specified as 2D-vector.

Definition at line 256 of file matrix3x3.h.

257{
258 m_data[0][2] = aTranslation.x;
259 m_data[1][2] = aTranslation.y;
260}

References VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by KIGFX::GAL::ComputeWorldScreenMatrix(), and KIGFX::CAIRO_PRINT_GAL::ComputeWorldScreenMatrix().

◆ Transpose()

template<class T >
MATRIX3x3< T > MATRIX3x3< T >::Transpose

Get the transpose of the matrix.

Returns
the transpose matrix.

Definition at line 405 of file matrix3x3.h.

406{
407 MATRIX3x3<T> result;
408
409 for( int i = 0; i < 3; i++ )
410 {
411 for( int j = 0; j < 3; j++ )
412 {
413 result.m_data[j][i] = m_data[i][j];
414 }
415 }
416
417 return result;
418}

References MATRIX3x3< T >::m_data.

Friends And Related Function Documentation

◆ operator

template<class T >
std::ostream & operator ( std::ostream &  aStream,
const MATRIX3x3< T > &  aMatrix 
)
friend

Output to a stream.

Equality operator

Member Data Documentation

◆ m_data


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