wxArt2D
Public Member Functions | Static Public Member Functions | Public Attributes | Static Protected Attributes | Friends | List of all members

A 2x3 affine matrix class for 2D transformations. More...

#include <afmatrix.h>

Collaboration diagram for a2dAffineMatrix:
Collaboration graph
[legend]

Public Member Functions

 a2dAffineMatrix (double xt, double yt, double scalex=1, double scaley=1, double degrees=0)
 constructor More...
 
 a2dAffineMatrix (double sx, double shx, double shy, double sy, double tx, double ty)
 
 a2dAffineMatrix (void)
 constructor (makes an identity matrix)
 
 a2dAffineMatrix (const a2dAffineMatrix &mat)
 constructor using other matrix
 
double GetValue (int col, int row) const
 get the value in the matrix at col,row More...
 
void SetValue (int col, int row, double value)
 set the value in the matrix at col,row More...
 
void operator= (const a2dAffineMatrix &mat)
 make the same
 
bool operator== (const a2dAffineMatrix &a)
 are they eqaul
 
bool operator!= (const a2dAffineMatrix &a)
 are they NOT eqaul
 
a2dAffineMatrixoperator*= (const a2dAffineMatrix &m)
 multiply matrix m with this
 
a2dAffineMatrix operator* (const a2dAffineMatrix &m) const
 multiply this by matrix m and return result
 
a2dAffineMatrix operator- (const a2dAffineMatrix &a)
 subtract two matrices More...
 
double & operator() (int col, int row)
 
double operator() (int col, int row) const
 
bool Invert (void)
 Invert matrix.
 
bool Identity (void)
 Make into identity matrix.
 
bool IsIdentity (void) const
 Is the matrix the identity matrix? More...
 
bool IsIdentity1 (void) const
 This does an actual check. More...
 
bool IsTranslate (void) const
 Is the matrix only a translation? More...
 
bool IsTranslateScaleIso (void) const
 
bool Scale (double scale)
 Scale by scale (isotropic scaling i.e. the same in x and y): More...
 
bool RemoveScale ()
 Remove Scale: More...
 
a2dAffineMatrixScale (const double &xs, const double &ys, const double &xc, const double &yc)
 Scale with center point and x/y scale. More...
 
a2dAffineMatrixMirror (bool y=true, bool x=false)
 mirror a matrix in x, y More...
 
bool Translate (double x, double y)
 Translate by dx, dy: More...
 
bool Rotate (double angle)
 Rotate clockwise by the given number of degrees: More...
 
bool SkewX (double degrees)
 Skew Xaxis: More...
 
bool SkewY (double degrees)
 Skew Yaxis: More...
 
a2dAffineMatrixRotate (const double &r, const double &x, const double &y)
 Rotate counter clockwise with point of rotation. More...
 
void TransformPoint (double x, double y, double &tx, double &ty) const
 Transform a point.
 
void TransformPoint (double &tx, double &ty) const
 Transform a point.
 
void TransformPoint (a2dPoint2D *point) const
 Transform a point.
 
void TransformPoint (const a2dPoint2D &src, a2dPoint2D *dest) const
 Transform a point.
 
void TransformVector (double dx, double dy, double &tdx, double &tdy) const
 Transform a vector. More...
 
double TransformDistance (double distance) const
 Transform a distance. More...
 
void TransformDistance (double &dx, double &dy) const
 Transform a distance.
 
double Get_scaleX () const
 return scaling in X
 
double Get_scaleY () const
 return scaling in Y
 
double GetRotation () const
 return rotation More...
 
void SetRotation (double rotation)
 set rotation More...
 
a2dPoint2D GetTranslation () const
 get the translation vector as a point
 
double GetDeterminant () const
 Calculate the determinat of the linear transformation.
 
double GetDeterminant1 () const
 Calculate the determinat of the shift vector and the transformed y-axis vector.
 
double GetDeterminant2 () const
 Calculate the determinat of the transformed x-axis vector and the shift vector.
 
double GetMaximum () const
 Calculate the maximum absolute of the elemnts entering GetDeterminant.
 
double GetMaximum1 () const
 Calculate the maximum absolute of the elemnts entering GetDeterminant1.
 
double GetMaximum2 () const
 Calculate the maximum absolute of the elemnts entering GetDeterminant2.
 
void DebugDump (const wxChar *text, double w, double h) const
 Dump the Matrix to a debug window.
 

Static Public Member Functions

static a2dAffineMatrix Mul (const a2dAffineMatrix &m1, const a2dAffineMatrix &m2)
 
static const a2dAffineMatrixGetIdentityMatrix ()
 Return a static identity matrix as reference.
 

Public Attributes

double m_matrix [3][2]
 array store the six double for the affine matrix
 
bool m_isIdentity
 true if identity matrix
 

Static Protected Attributes

static const a2dAffineMatrix sm_Identity
 A static identity matrix in case an identity matrix is to be returned as reference.
 

Friends

bool operator== (const a2dAffineMatrix &a, const a2dAffineMatrix &b)
 are they eqaul
 
bool operator!= (const a2dAffineMatrix &a, const a2dAffineMatrix &b)
 are they NOT eqaul
 
a2dAffineMatrix operator- (const a2dAffineMatrix &a, const a2dAffineMatrix &b)
 subtract two matrices
 

Detailed Description

A 2x3 affine matrix class for 2D transformations.

A 2x3 matrix to do 2D transformations.

It follows a 'column vector' convention, more or less. A point P=(x,y) is treated as the transpose of [x, y, 1], and transformation is accomplished by pre-multiplication by the transformation matrix M:

                [ sx  shx  tx ]   [x]
     [x',y'] =  [ shy  sy  ty ] * [y] = [sx*x+shx*y+tx, shy*x+sy*y+ty]
                                  [1]

It is only "more-or-less" so because accessors of this class use a convention of (col,row), which is backwards from normal mathematical notation. The actual memory layout is double[3][2], which means it's stored column-major: {sx, shy, shx, sy, tx, ty}.

It can be used to map data to window coordinates. But also for manipulating your own 2D data. Because this class is specialy designed to do 2D transformations a lot of things could be optimized for this particlular purpose. For example drawing a picture (composed of several primitives) at a certain coordinate and angle within another parent picture. At all times m_isIdentity is set if the matrix itself is an Identity matrix. m_isIdentity is used where possible to optimize calculations.

Definition at line 53 of file afmatrix.h.

Constructor & Destructor Documentation

a2dAffineMatrix::a2dAffineMatrix ( double  xt,
double  yt,
double  scalex = 1,
double  scaley = 1,
double  degrees = 0 
)

constructor

Initialize matrix.

First a translation is proceed after this a scalling at that position followed by a rotation at that position.

Parameters
xttranslation in x
yttranslation in y
scalexscaling in x
scaleyscaling in y
degreesrotation clockwise

Definition at line 53 of file afmatrix.cpp.

Member Function Documentation

double a2dAffineMatrix::GetRotation ( ) const

return rotation

Returns the absolute rotation in the range 179.999... to 180 degrees

See Also
SetRotation

Definition at line 799 of file afmatrix.cpp.

double a2dAffineMatrix::GetValue ( int  col,
int  row 
) const

get the value in the matrix at col,row

rows are horizontal (second index of m_matrix member) columns are vertical (first index of m_matrix member)

Definition at line 106 of file afmatrix.cpp.

bool a2dAffineMatrix::IsIdentity ( void  ) const
inline

Is the matrix the identity matrix?

Only returns a flag, which is set whenever an operation

is done.

Definition at line 147 of file afmatrix.h.

bool a2dAffineMatrix::IsIdentity1 ( void  ) const
inline

This does an actual check.

Is the matrix the identity matrix? Each operation checks whether the result is still the identity matrix and sets a flag.

Definition at line 347 of file afmatrix.h.

bool a2dAffineMatrix::IsTranslate ( void  ) const
inline

Is the matrix only a translation?

checks the matrix to see if it only does a traslation.

Definition at line 359 of file afmatrix.h.

a2dAffineMatrix & a2dAffineMatrix::Mirror ( bool  y = true,
bool  x = false 
)

mirror a matrix in x, y

ex:

           | -1     0      0 |
 matrix' = |  0    -1      0 | x matrix
           |  0     0      1 |

Definition at line 396 of file afmatrix.cpp.

double & a2dAffineMatrix::operator() ( int  col,
int  row 
)

rows are horizontal (second index of m_matrix member) columns are vertical (first index of m_matrix member)

Definition at line 174 of file afmatrix.cpp.

double a2dAffineMatrix::operator() ( int  col,
int  row 
) const

rows are horizontal (second index of m_matrix member) columns are vertical (first index of m_matrix member)

Definition at line 182 of file afmatrix.cpp.

a2dAffineMatrix a2dAffineMatrix::operator- ( const a2dAffineMatrix a)

subtract two matrices

matrixes subtract

Definition at line 726 of file afmatrix.cpp.

bool a2dAffineMatrix::RemoveScale ( )

Remove Scale:

ex:

          | 1/sqrt(det) 0           0      |
matrix' = | 0           1/sqrt(det) 0      | x matrix
          | 0           0           1      |

Definition at line 290 of file afmatrix.cpp.

bool a2dAffineMatrix::Rotate ( double  angle)

Rotate clockwise by the given number of degrees:

Rotates clockwise: If you call Rotate(20); Rotate(10); the absolute rotation is 30 degrees (if the initially rotation was 0)

See Also
SetRotation

:

           |  cos sin 0 |
 matrix' = | -sin cos 0 | x matrix
           |   0   0  1 |

Definition at line 432 of file afmatrix.cpp.

a2dAffineMatrix & a2dAffineMatrix::Rotate ( const double &  r,
const double &  x,
const double &  y 
)

Rotate counter clockwise with point of rotation.

ex:

           |  cos(r) -sin(r)    x(1-cos(r))+y(sin(r)|
 matrix' = |  sin(r)  cos(r)    y(1-cos(r))-x(sin(r)| x matrix
           |   0          0                       1 |

Definition at line 484 of file afmatrix.cpp.

bool a2dAffineMatrix::Scale ( double  scale)

Scale by scale (isotropic scaling i.e. the same in x and y):

ex:

           | scale  0      0      |
 matrix' = |  0     scale  0      | x matrix
           |  0     0      scale  |

Definition at line 270 of file afmatrix.cpp.

a2dAffineMatrix & a2dAffineMatrix::Scale ( const double &  xs,
const double &  ys,
const double &  xc,
const double &  yc 
)

Scale with center point and x/y scale.

ex:

           |  xs    0      xc(1-xs) |
 matrix' = |  0    ys      yc(1-ys) | x matrix
           |  0     0      1        |

Definition at line 327 of file afmatrix.cpp.

void a2dAffineMatrix::SetRotation ( double  rotation)

set rotation

In opposite to Rotate this method sets an absolute rotation.

See Also
Rotate

Definition at line 815 of file afmatrix.cpp.

void a2dAffineMatrix::SetValue ( int  col,
int  row,
double  value 
)

set the value in the matrix at col,row

rows are horizontal (second index of m_matrix member) columns are vertical (first index of m_matrix member)

Definition at line 114 of file afmatrix.cpp.

bool a2dAffineMatrix::SkewX ( double  degrees)

Skew Xaxis:

ex:

           |   1   tan(a) 0 |
 matrix' = |   0   1      0 | x matrix
           |   0   0      1 |

Definition at line 441 of file afmatrix.cpp.

bool a2dAffineMatrix::SkewY ( double  degrees)

Skew Yaxis:

ex:

           |     1    0      0 |
 matrix' = | tan(a)   1      0 | x matrix
           |     0    0      1 |

Definition at line 460 of file afmatrix.cpp.

double a2dAffineMatrix::TransformDistance ( double  distance) const

Transform a distance.

This transforms a relative distance. A horizontal and vertical line starting at the origin, and distance long, is transformed. The length of the line with the minimum distance in the transformed space is returned.

Parameters
distancedistance to transform
Returns
transformed distance

Definition at line 616 of file afmatrix.cpp.

void a2dAffineMatrix::TransformVector ( double  dx,
double  dy,
double &  tdx,
double &  tdy 
) const

Transform a vector.

This transforms a free vector. It is equivalent to transforming the two points (px,py) and (px+dx,py+dy) and then subtracting the former from the latter. In effect this means it ignores the translation portion of the matrix, and just multiplies by the core 2x2 linear transform.

Definition at line 602 of file afmatrix.cpp.

bool a2dAffineMatrix::Translate ( double  x,
double  y 
)

Translate by dx, dy:

ex:

           | 1  0 dx |
 matrix' = | 0  1 dy | x matrix
           | 0  0  1 |

Definition at line 420 of file afmatrix.cpp.


The documentation for this class was generated from the following files:
a2dAffineMatrix Class Reference -- Sun Oct 12 2014 17:04:27 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation