ActivateEvent

#### Next topic

AffineMatrix2DBase

# AffineMatrix2D¶

A 3x2 matrix representing an affine 2D transformation.

New in version 2.9.2.

## Inheritance Diagram¶

Inheritance diagram for class AffineMatrix2D

## Methods Summary¶

 __init__ Default constructor. Concat Concatenate this matrix with another one. Get Get the component values of the matrix. Invert Invert this matrix. IsEqual Check that this matrix is identical with . IsIdentity Check if this is the identity matrix. Mirror Add mirroring to this matrix. Rotate Add clockwise rotation to this matrix. Scale Add scaling to this matrix. Set Set all elements of this matrix. TransformDistance Applies the linear part of this matrix, i.e. TransformPoint Applies this matrix to the point. Translate Add the translation to this matrix. __ne__ Check that this matrix differs from . __eq__ Check that this matrix is identical with .

## Class API¶

class AffineMatrix2D(AffineMatrix2DBase)

A 3x2 matrix representing an affine 2D transformation.

Possible constructors:

```AffineMatrix2D()
```

### Methods¶

__init__(self)

Default constructor.

The matrix elements are initialize to the identity matrix.

Concat(self, t)

Concatenate this matrix with another one.

The parameter matrix is the multiplicand.

Parameters: t (AffineMatrix2DBase) – The multiplicand.
```#           | t.m_11  t.m_12  0 |   | m_11  m_12   0 |
# matrix' = | t.m_21  t.m_22  0 | x | m_21  m_22   0 |
#           | t.m_tx  t.m_ty  1 |   | m_tx  m_ty   1 |
```

Get(self)

Get the component values of the matrix.

The rotational components of the matrix (upper 2 x 2), must be not None.

The translational components of the matrix, may be None.

Return type: tuple ( mat2D, tr )

Invert(self)

Invert this matrix.

If the matrix is not invertible, i.e. if its determinant is 0, returns False and doesn’t modify it.

```#           | m_11  m_12  0 |
# Invert    | m_21  m_22  0 |
#           | m_tx  m_ty  1 |
```
Return type: bool

IsEqual(self, t)

Check that this matrix is identical with .

Parameters: t (AffineMatrix2DBase) – The matrix compared with this.

IsIdentity(self)

Check if this is the identity matrix.

Return type: bool

Mirror(self, direction=HORIZONTAL)

Parameters: direction (int) – The direction(s) used for mirroring. One of HORIZONTAL, VERTICAL or their combination BOTH.

Add clockwise rotation to this matrix.

```#           | cos    sin   0 |   | self.11  self.12   0 |
# matrix' = | -sin   cos   0 | x | self.21  self.22   0 |
#           |  0      0    1 |   | self.tx  self.ty   1 |
```

Scale(self, xScale, yScale)

Parameters: xScale (float) – Scaling in x direction. yScale (float) – Scaling in y direction.
```#           | xScale   0      0 |   | self.11  self.12   0 |
# matrix' = |   0    yScale   0 | x | self.21  self.22   0 |
#           |   0      0      1 |   | self.tx  self.ty   1 |
```

Set(self, mat2D, tr)

Set all elements of this matrix.

Parameters: mat2D (Matrix2D) – The rotational components of the matrix (upper 2 x 2). tr (Point2DDouble) – The translational components of the matrix.

TransformDistance(self, *args, **kw)

TransformDistance (self, p)

Applies the linear part of this matrix, i.e.

without translation.

Parameters: p (Point2DDouble) – The source receiving the transformations. Point2DDouble
```#                                   | self.11  self.12   0 |
# dist' = | src.self.x  src._my  0 | x | self.21  self.22   0 |
#                                   | self.tx  self.ty   1 |
```
Returns: The source with the transformations applied.

TransformDistance (self, dx, dy)

Parameters: dx (float) – dy (float) – tuple ( dx, dy )

TransformPoint(self, *args, **kw)

TransformPoint (self, p)

Applies this matrix to the point.

Parameters: p (Point2DDouble) – The point receiving the transformations. Point2DDouble
```#                                    | self.11  self.12   0 |
# point' = | src.self.x  src._my  1 | x | self.21  self.22   0 |
#                                    | self.tx  self.ty   1 |
```
Returns: The point with the transformations applied.

TransformPoint (self, x, y)

Parameters: x (float) – y (float) – tuple ( x, y )

Translate(self, dx, dy)

Add the translation to this matrix.

Parameters: dx (float) – The translation in x direction. dy (float) – The translation in y direction.
```#           |  1   0   0 |   | self.11  self.12   0 |
# matrix' = |  0   1   0 | x | self.21  self.22   0 |
#           | dx  dy   1 |   | self.tx  self.ty   1 |
```

__ne__(self)

Check that this matrix differs from .

Parameters: t (AffineMatrix2DBase) – The matrix compared with this.

__eq__(self)

Check that this matrix is identical with .

Parameters: t (AffineMatrix2DBase) – The matrix compared with this.