cairomm 1.18.0
Public Member Functions | Related Functions | List of all members
Cairo::Matrix Class Reference

A Transformation matrix. More...

#include <cairomm/matrix.h>

Inheritance diagram for Cairo::Matrix:
Inheritance graph
[legend]

Public Member Functions

 Matrix ()
 Creates an uninitialized matrix. More...
 
 Matrix (double xx, double yx, double xy, double yy, double x0, double y0)
 Creates a matrix Sets to be the affine transformation given by xx, yx, xy, yy, x0, y0. More...
 
void translate (double tx, double ty)
 Applies a translation by tx, ty to the transformation in matrix. More...
 
void scale (double sx, double sy)
 Applies scaling by sx, sy to the transformation in matrix. More...
 
void rotate (double radians)
 Applies rotation by radians to the transformation in matrix. More...
 
void invert ()
 Changes matrix to be the inverse of it's original value. More...
 
void multiply (Matrix & a, Matrix & b)
 Multiplies the affine transformations in a and b together and stores the result in this matrix. More...
 
void transform_distance (double & dx, double & dy) const
 Transforms the distance vector (dx,dy) by matrix. More...
 
void transform_point (double & x, double & y) const
 Transforms the point (x, y) by this matrix. More...
 

Related Functions

(Note that these are not member functions.)

Matrix identity_matrix ()
 Returns a Matrix initialized to the identity matrix. More...
 
Matrix translation_matrix (double tx, double ty)
 Returns a Matrix initialized to a transformation that translates by tx and ty in the X and Y dimensions, respectively. More...
 
Matrix scaling_matrix (double sx, double sy)
 Returns a Matrix initialized to a transformation that scales by sx and sy in the X and Y dimensions, respectively. More...
 
Matrix rotation_matrix (double radians)
 Returns a Matrix initialized to a transformation that rotates by radians. More...
 
Matrix operator* (const Matrix & a, const Matrix & b)
 Multiplies the affine transformations in a and b together and returns the result. More...
 

Detailed Description

A Transformation matrix.

Cairo::Matrix is used throughout cairomm to convert between different coordinate spaces. A Matrix holds an affine transformation, such as a scale, rotation, shear, or a combination of these. The transformation of a point (x,y) is given by:

x_new = xx * x + xy * y + x0;
y_new = yx * x + yy * y + y0;

The current transformation matrix of a Context, represented as a Matrix, defines the transformation from user-space coordinates to device-space coordinates.

See also
Context::get_matrix()
Context::set_matrix()

Constructor & Destructor Documentation

◆ Matrix() [1/2]

Cairo::Matrix::Matrix ( )

Creates an uninitialized matrix.

If you want a matrix initialized to a certain value, either specify the values explicitly with the other constructor or use one of the free functions for initializing matrices with specific scales, rotations, etc.

See also
identity_matrix()
rotation_matrix()
translation_matrix()
scaling_matrix()

◆ Matrix() [2/2]

Cairo::Matrix::Matrix ( double  xx,
double  yx,
double  xy,
double  yy,
double  x0,
double  y0 
)

Creates a matrix Sets to be the affine transformation given by xx, yx, xy, yy, x0, y0.

The transformation is given by:

x_new = xx * x + xy * y + x0;
y_new = yx * x + yy * y + y0;
Parameters
xxxx component of the affine transformation
yxyx component of the affine transformation
xyxy component of the affine transformation
yyyy component of the affine transformation
x0X translation component of the affine transformation
y0Y translation component of the affine transformation

Member Function Documentation

◆ invert()

void Cairo::Matrix::invert ( )

Changes matrix to be the inverse of it's original value.

Not all transformation matrices have inverses; if the matrix collapses points together (it is degenerate), then it has no inverse and this function will throw an exception.

Exceptions

◆ multiply()

void Cairo::Matrix::multiply ( Matrix a,
Matrix b 
)

Multiplies the affine transformations in a and b together and stores the result in this matrix.

The effect of the resulting transformation is to first apply the transformation in a to the coordinates and then apply the transformation in b to the coordinates.

It is allowable for result to be identical to either a or b.

Parameters
aa Matrix
ba Matrix
See also
operator*()

◆ rotate()

void Cairo::Matrix::rotate ( double  radians)

Applies rotation by radians to the transformation in matrix.

The effect of the new transformation is to first rotate the coordinates by radians, then apply the original transformation to the coordinates.

Parameters
radiansangle of rotation, in radians. The direction of rotation is defined such that positive angles rotate in the direction from the positive X axis toward the positive Y axis. With the default axis orientation of cairo, positive angles rotate in a clockwise direction.

◆ scale()

void Cairo::Matrix::scale ( double  sx,
double  sy 
)

Applies scaling by sx, sy to the transformation in matrix.

The effect of the new transformation is to first scale the coordinates by sx and sy, then apply the original transformation to the coordinates.

Parameters
sxscale factor in the X direction
syscale factor in the Y direction

◆ transform_distance()

void Cairo::Matrix::transform_distance ( double &  dx,
double &  dy 
) const

Transforms the distance vector (dx,dy) by matrix.

This is similar to transform_point() except that the translation components of the transformation are ignored. The calculation of the returned vector is as follows:

dx2 = dx1 * a + dy1 * c;
dy2 = dx1 * b + dy1 * d;

Affine transformations are position invariant, so the same vector always transforms to the same vector. If (x1,y1) transforms to (x2,y2) then (x1+dx1,y1+dy1) will transform to (x1+dx2,y1+dy2) for all values of x1 and x2.

Parameters
dxX component of a distance vector. An in/out parameter
dyY component of a distance vector. An in/out parameter

◆ transform_point()

void Cairo::Matrix::transform_point ( double &  x,
double &  y 
) const

Transforms the point (x, y) by this matrix.

Parameters
xX position. An in/out parameter
yY position. An in/out parameter

◆ translate()

void Cairo::Matrix::translate ( double  tx,
double  ty 
)

Applies a translation by tx, ty to the transformation in matrix.

The effect of the new transformation is to first translate the coordinates by tx and ty, then apply the original transformation to the coordinates.

Parameters
txamount to translate in the X direction
tyamount to translate in the Y direction

Friends And Related Function Documentation

◆ identity_matrix()

Matrix identity_matrix ( )
related

Returns a Matrix initialized to the identity matrix.

◆ operator*()

Matrix operator* ( const Matrix a,
const Matrix b 
)
related

Multiplies the affine transformations in a and b together and returns the result.

The effect of the resulting transformation is to first apply the transformation in a to the coordinates and then apply the transformation in b to the coordinates.

It is allowable for result to be identical to either a or b.

Parameters
aa Matrix
ba Matrix

◆ rotation_matrix()

Matrix rotation_matrix ( double  radians)
related

Returns a Matrix initialized to a transformation that rotates by radians.

Parameters
radiansangle of rotation, in radians. The direction of rotation is defined such that positive angles rotate in the direction from the positive X axis toward the positive Y axis. With the default axis orientation of cairo, positive angles rotate in a clockwise direction.

◆ scaling_matrix()

Matrix scaling_matrix ( double  sx,
double  sy 
)
related

Returns a Matrix initialized to a transformation that scales by sx and sy in the X and Y dimensions, respectively.

Parameters
sxscale factor in the X direction
syscale factor in the Y direction

◆ translation_matrix()

Matrix translation_matrix ( double  tx,
double  ty 
)
related

Returns a Matrix initialized to a transformation that translates by tx and ty in the X and Y dimensions, respectively.

Parameters
txamount to translate in the X direction
tyamount to translate in the Y direction

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