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 (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...
 

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 61 of file matrix3x3.h.

Constructor & Destructor Documentation

◆ MATRIX3x3() [1/2]

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

Initialize all matrix members to zero.

Definition at line 180 of file matrix3x3.h.

181{
182 for( int j = 0; j < 3; j++ )
183 {
184 for( int i = 0; i < 3; i++ )
185 {
186 m_data[i][j] = 0.0;
187 }
188 }
189}
T m_data[3][3]
Definition: matrix3x3.h:64

◆ MATRIX3x3() [2/2]

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 193 of file matrix3x3.h.

194{
195 m_data[0][0] = a00;
196 m_data[0][1] = a01;
197 m_data[0][2] = a02;
198
199 m_data[1][0] = a10;
200 m_data[1][1] = a11;
201 m_data[1][2] = a12;
202
203 m_data[2][0] = a20;
204 m_data[2][1] = a21;
205 m_data[2][2] = a22;
206}

Member Function Documentation

◆ Determinant()

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

Compute the determinant of the matrix.

Returns
the determinant value.

Definition at line 306 of file matrix3x3.h.

307{
308 return m_data[0][0] * ( m_data[1][1] * m_data[2][2] - m_data[1][2] * m_data[2][1] )
309 - m_data[0][1] * ( m_data[1][0] * m_data[2][2] - m_data[1][2] * m_data[2][0] )
310 + m_data[0][2] * ( m_data[1][0] * m_data[2][1] - m_data[1][1] * m_data[2][0] );
311}

◆ 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 265 of file matrix3x3.h.

266{
267 VECTOR2<T> result( m_data[0][0], m_data[1][1] );
268
269 return result;
270}
Define a general 2D-vector/point.
Definition: vector2d.h:74

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 234 of file matrix3x3.h.

235{
236 VECTOR2<T> result;
237 result.x = m_data[0][2];
238 result.y = m_data[1][2];
239
240 return result;
241}

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 339 of file matrix3x3.h.

340{
341 MATRIX3x3<T> result;
342
343 result.m_data[0][0] = m_data[1][1] * m_data[2][2] - m_data[2][1] * m_data[1][2];
344 result.m_data[0][1] = m_data[0][2] * m_data[2][1] - m_data[2][2] * m_data[0][1];
345 result.m_data[0][2] = m_data[0][1] * m_data[1][2] - m_data[1][1] * m_data[0][2];
346
347 result.m_data[1][0] = m_data[1][2] * m_data[2][0] - m_data[2][2] * m_data[1][0];
348 result.m_data[1][1] = m_data[0][0] * m_data[2][2] - m_data[2][0] * m_data[0][2];
349 result.m_data[1][2] = m_data[0][2] * m_data[1][0] - m_data[1][2] * m_data[0][0];
350
351 result.m_data[2][0] = m_data[1][0] * m_data[2][1] - m_data[2][0] * m_data[1][1];
352 result.m_data[2][1] = m_data[0][1] * m_data[2][0] - m_data[2][1] * m_data[0][0];
353 result.m_data[2][2] = m_data[0][0] * m_data[1][1] - m_data[1][0] * m_data[0][1];
354
355 return result * ( 1.0 / Determinant() );
356}
MATRIX3x3 describes a general 3x3 matrix.
Definition: matrix3x3.h:62
T Determinant() const
Compute the determinant of the matrix.
Definition: matrix3x3.h:306

References MATRIX3x3< T >::m_data.

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

◆ 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 210 of file matrix3x3.h.

211{
212 for( int j = 0; j < 3; j++ )
213 {
214 for( int i = 0; i < 3; i++ )
215 {
216 if( i == j )
217 m_data[i][j] = 1.0;
218 else
219 m_data[i][j] = 0.0;
220 }
221 }
222}

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 245 of file matrix3x3.h.

246{
247 T cosValue = cos( aAngle );
248 T sinValue = sin( aAngle );
249 m_data[0][0] = cosValue;
250 m_data[0][1] = -sinValue;
251 m_data[1][0] = sinValue;
252 m_data[1][1] = cosValue;
253}

Referenced by 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 257 of file matrix3x3.h.

258{
259 m_data[0][0] = aScale.x;
260 m_data[1][1] = aScale.y;
261}

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 226 of file matrix3x3.h.

227{
228 m_data[0][2] = aTranslation.x;
229 m_data[1][2] = aTranslation.y;
230}

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 360 of file matrix3x3.h.

361{
362 MATRIX3x3<T> result;
363
364 for( int i = 0; i < 3; i++ )
365 {
366 for( int j = 0; j < 3; j++ )
367 {
368 result.m_data[j][i] = m_data[i][j];
369 }
370 }
371
372 return result;
373}

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.

Member Data Documentation

◆ m_data


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