KiCad PCB EDA Suite
MATRIX3x3< T > Class Template Reference

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

#include <matrix3x3.h>

Public Member Functions

 MATRIX3x3 ()
 Constructor. More...
 
 MATRIX3x3 (T a00, T a01, T a02, T a10, T a11, T a12, T a20, T a21, T a22)
 Constructor. 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 >

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

Constructor & Destructor Documentation

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

Constructor.

Initialize all matrix members to zero.

Definition at line 184 of file matrix3x3.h.

185 {
186  for( int j = 0; j < 3; j++ )
187  {
188  for( int i = 0; i < 3; i++ )
189  {
190  m_data[i][j] = 0.0;
191  }
192  }
193 }
T m_data[3][3]
Definition: matrix3x3.h:64
template<class T>
MATRIX3x3< T >::MATRIX3x3 ( a00,
a01,
a02,
a10,
a11,
a12,
a20,
a21,
a22 
)

Constructor.

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

198 {
199  m_data[0][0] = a00;
200  m_data[0][1] = a01;
201  m_data[0][2] = a02;
202 
203  m_data[1][0] = a10;
204  m_data[1][1] = a11;
205  m_data[1][2] = a12;
206 
207  m_data[2][0] = a20;
208  m_data[2][1] = a21;
209  m_data[2][2] = a22;
210 }
T m_data[3][3]
Definition: matrix3x3.h:64

Member Function Documentation

template<class T >
T MATRIX3x3< T >::Determinant ( ) const

Compute the determinant of the matrix.

Returns
the determinant value.

Definition at line 310 of file matrix3x3.h.

311 {
312  return m_data[0][0] * ( m_data[1][1] * m_data[2][2] - m_data[1][2] * m_data[2][1] )
313  - m_data[0][1] * ( m_data[1][0] * m_data[2][2] - m_data[1][2] * m_data[2][0] )
314  + m_data[0][2] * ( m_data[1][0] * m_data[2][1] - m_data[1][1] * m_data[2][0] );
315 }
T m_data[3][3]
Definition: matrix3x3.h:64
template<class T >
VECTOR2< T > MATRIX3x3< T >::GetScale ( ) const

Get the scale components of the matrix.

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

Definition at line 269 of file matrix3x3.h.

Referenced by KIGFX::VIEW::ToScreen(), and KIGFX::VIEW::ToWorld().

270 {
271  VECTOR2<T> result( m_data[0][0], m_data[1][1] );
272 
273  return result;
274 }
Class VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:65
T m_data[3][3]
Definition: matrix3x3.h:64
template<class T >
VECTOR2< T > MATRIX3x3< T >::GetTranslation ( ) const

Get the translation components of the matrix.

Returns
is the translation (2D-vector).

Definition at line 238 of file matrix3x3.h.

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

239 {
240  VECTOR2<T> result;
241  result.x = m_data[0][2];
242  result.y = m_data[1][2];
243 
244  return result;
245 }
Class VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:65
T m_data[3][3]
Definition: matrix3x3.h:64
template<class T >
MATRIX3x3< T > MATRIX3x3< T >::Inverse ( ) const

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

References MATRIX3x3< T >::m_data.

Referenced by KIGFX::GAL::ComputeWorldScreenMatrix().

344 {
345  MATRIX3x3<T> result;
346 
347  result.m_data[0][0] = m_data[1][1] * m_data[2][2] - m_data[2][1] * m_data[1][2];
348  result.m_data[0][1] = m_data[0][2] * m_data[2][1] - m_data[2][2] * m_data[0][1];
349  result.m_data[0][2] = m_data[0][1] * m_data[1][2] - m_data[1][1] * m_data[0][2];
350 
351  result.m_data[1][0] = m_data[1][2] * m_data[2][0] - m_data[2][2] * m_data[1][0];
352  result.m_data[1][1] = m_data[0][0] * m_data[2][2] - m_data[2][0] * m_data[0][2];
353  result.m_data[1][2] = m_data[0][2] * m_data[1][0] - m_data[1][2] * m_data[0][0];
354 
355  result.m_data[2][0] = m_data[1][0] * m_data[2][1] - m_data[2][0] * m_data[1][1];
356  result.m_data[2][1] = m_data[0][1] * m_data[2][0] - m_data[2][1] * m_data[0][0];
357  result.m_data[2][2] = m_data[0][0] * m_data[1][1] - m_data[1][0] * m_data[0][1];
358 
359  return result * ( 1.0 / Determinant() );
360 }
T m_data[3][3]
Definition: matrix3x3.h:64
T Determinant() const
Compute the determinant of the matrix.
Definition: matrix3x3.h:310
Class MATRIX3x3 describes a general 3x3 matrix.
Definition: matrix3x3.h:55
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 214 of file matrix3x3.h.

Referenced by KIGFX::GAL::ComputeWorldScreenMatrix().

215 {
216  for( int j = 0; j < 3; j++ )
217  {
218  for( int i = 0; i < 3; i++ )
219  {
220  if( i == j )
221  m_data[i][j] = 1.0;
222  else
223  m_data[i][j] = 0.0;
224  }
225  }
226 }
T m_data[3][3]
Definition: matrix3x3.h:64
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 249 of file matrix3x3.h.

250 {
251  T cosValue = cos( aAngle );
252  T sinValue = sin( aAngle );
253  m_data[0][0] = cosValue;
254  m_data[0][1] = -sinValue;
255  m_data[1][0] = sinValue;
256  m_data[1][1] = cosValue;
257 }
T
enum T contains all this lexer's tokens.
T m_data[3][3]
Definition: matrix3x3.h:64
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 261 of file matrix3x3.h.

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

Referenced by KIGFX::GAL::ComputeWorldScreenMatrix().

262 {
263  m_data[0][0] = aScale.x;
264  m_data[1][1] = aScale.y;
265 }
T m_data[3][3]
Definition: matrix3x3.h:64
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 230 of file matrix3x3.h.

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

Referenced by KIGFX::GAL::ComputeWorldScreenMatrix().

231 {
232  m_data[0][2] = aTranslation.x;
233  m_data[1][2] = aTranslation.y;
234 }
T m_data[3][3]
Definition: matrix3x3.h:64
template<class T >
MATRIX3x3< T > MATRIX3x3< T >::Transpose ( ) const

Get the transpose of the matrix.

Returns
the transpose matrix.

Definition at line 364 of file matrix3x3.h.

References MATRIX3x3< T >::m_data.

365 {
366  MATRIX3x3<T> result;
367 
368  for( int i = 0; i < 3; i++ )
369  {
370  for( int j = 0; j < 3; j++ )
371  {
372  result.m_data[j][i] = m_data[i][j];
373  }
374  }
375 
376  return result;
377 }
T m_data[3][3]
Definition: matrix3x3.h:64
Class MATRIX3x3 describes a general 3x3 matrix.
Definition: matrix3x3.h:55

Friends And Related Function Documentation

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

Output to a stream.

Member Data Documentation


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