Inherits from NSObject
Conforms to NSCopying
PXPooledObject
Declared in PXMatrix.h
PXMatrix.m

Overview

A PXMatrix object that represents a two-dimensional transformation matrix.

The following code creates an identity matrix:

PXMatrix *matrix = [PXMatrix new];

The following code creates a matrix that has been rotated 30 degrees (PI/6.0f radians) and translated (-4.0f, 2.5f):

PXMatrix *matrix = [[PXMatrix alloc] initWithA:0.866025f b:0.5f c:0.5f d:0.866025f tx:-4.0f ty:2.5f];

Likewise the following code creates a matrix that has been rotated 30 degrees (PI/6.0f radians) and translated (-4.0f, 2.5f):

PXMatrix *matrix = [PXMatrix new];
[matrix rotate:M_PI/6.0f];
[matrix translateX:-4.0f y:2.5f];

Tasks

  •   a

    The value that affects the positioning of pixels along the x-axis when scaling or rotating the matrix.

    property
  •   b

    The value that affects the positioning of pixels along the y-axis when skewing or rotating the matrix.

    property
  •   c

    The value that affects the positioning of pixels along the x-axis when skewing or rotating the matrix.

    property
  •   d

    The value that affects the positioning of pixels along the y-axis when scaling or rotating the matrix.

    property
  •   tx

    The value that affects the positioning of pixels along the x-axis when translating the matrix.

    property
  •   ty

    The value that affects the positioning of pixels along the y-axis when translating the matrix.

    property
  • – initWithA:b:c:d:tx:ty:

    Creates a new matrix with values of (a, b, c, d, tx, ty).

  • – setA:b:c:d:tx:ty:

    Sets the matrix values to (a, b, c, d, tx, ty).

  • – concat:

    Concatenates the specified matrix with this matrix, this is the same as multiplying the specified matrix with this matrix.

  • – identity

    Sets the values of the matrix to (a=1, b=0, c=0, d=1, tx=0, ty=0).

  • – invert

    Inverts the matrix. If the matrix is not invertible then the matrix is set back to identity.

  • – rotate:

    Rotates the matrix.

  • – scaleX:y:

    Scales the matrix.

  • – translateX:y:

    Translates the matrix.

  • – createBoxWithScaleX:scaleY:rotation:tx:ty:

    Using the create box method is the same as if you were to call identity, rotate, scale and translate in succession.

  • – transformPoint:

    Returns a point transformed by this matrix.

  • – deltaTransformPoint:

    Returns a point transformed by this matrix, ignoring the tx and ty parameters.

  • + matrixWithA:b:c:d:tx:ty:

    Creates a matrix with values of (a, b, c, d, tx, ty).

  • + identityMatrix

    Creates a matrix with values of (a=1.0, b=0.0, c=0.0, d=1.0, tx=0.0, ty=0.0)

Properties

a

The value that affects the positioning of pixels along the x-axis when scaling or rotating the matrix.

@property (nonatomic) float a

Declared In

PXMatrix.h

b

The value that affects the positioning of pixels along the y-axis when skewing or rotating the matrix.

@property (nonatomic) float b

Declared In

PXMatrix.h

c

The value that affects the positioning of pixels along the x-axis when skewing or rotating the matrix.

@property (nonatomic) float c

Declared In

PXMatrix.h

d

The value that affects the positioning of pixels along the y-axis when scaling or rotating the matrix.

@property (nonatomic) float d

Declared In

PXMatrix.h

tx

The value that affects the positioning of pixels along the x-axis when translating the matrix.

@property (nonatomic) float tx

Declared In

PXMatrix.h

ty

The value that affects the positioning of pixels along the y-axis when translating the matrix.

@property (nonatomic) float ty

Declared In

PXMatrix.h

Class Methods

identityMatrix

Creates a matrix with values of (a=1.0, b=0.0, c=0.0, d=1.0, tx=0.0, ty=0.0)

+ (PXMatrix *)identityMatrix

Discussion

Example:

PXMatrix *matrix = [PXMatrix identityMatrix];
// matrix will be (a=1.0f, b=0.0f, c=0.0f, d=1.0f, tx=0.0f, ty=0.0f)

Declared In

PXMatrix.m

matrixWithA:b:c:d:tx:ty:

Creates a matrix with values of (a, b, c, d, tx, ty).

+ (PXMatrix *)matrixWithA:(float)a b:(float)b c:(float)c d:(float)d tx:(float)tx ty:(float)ty

Parameters

a

The value that affects the positioning of pixels along the x-axis when scaling or rotating.

b

The value that affects the positioning of pixels along the y-axis when skewing or rotating.

c

The value that affects the positioning of pixels along the x-axis when skewing or rotating.

d

The value that affects the positioning of pixels along the y-axis when scaling or rotating.

tx

The value that affects the positioning of pixels along the x-axis when translating.

ty

The value that affects the positioning of pixels along the y-axis when translating.

Return Value

The created matrix.

Example:

PXMatrix *matrix = [PXMatrix matrixWithA:0.866025f b:0.5f c:0.5f d:0.866025f tx:-4.0f ty:2.5f];
// matrix will be (a=0.866025f, b=0.5f, c=0.5f, d=0.866025f, tx=-4.0f, ty=2.5f)

Declared In

PXMatrix.m

Instance Methods

concat:

Concatenates the specified matrix with this matrix, this is the same as multiplying the specified matrix with this matrix.

- (void)concat:(PXMatrix *)m

Parameters

m

The matrix to be concatenated.

Example:

PXMatrix *matrix1 = [[PXMatrix alloc] initWithA:0.866025f b:0.5f c:0.5f d:0.866025f tx:-4.0f ty:2.5f];
// matrix1 will be (a=0.866025f, b=0.5f, c=0.5f, d=0.866025f, tx=-4.0f, ty=2.5f)
PXMatrix *matrix2 = [[PXMatrix alloc] initWithA:0.0f b:1.0f c:1.0f d:0.0f tx:-1.0f ty:1.0f];
// matrix2 will be (a=0.0f, b=1.0f, c=1.0f, d=0.0f, tx=1.0f, ty=3.0f)
[matrix1 concat:matrix2];
// matrix1 will be (a=0.5f, b=0.866025f, c=0.866025f, d=0.5f, tx=-4.366030f, ty=2.866030f)

Declared In

PXMatrix.m

createBoxWithScaleX:scaleY:rotation:tx:ty:

Using the create box method is the same as if you were to call identity, rotate, scale and translate in succession.

- (void)createBoxWithScaleX:(float)_scaleX scaleY:(float)_scaleY rotation:(float)_rotation tx:(float)_tx ty:(float)_ty

Parameters

rotation

The angle of rotation in radians.

ty

The vertical translation.

Example:

PXMatrix *matrix = [[PXMatrix alloc] initWithA:0.866025f b:0.5f c:0.5f d:0.866025f tx:-4.0f ty:2.5f];
// matrix will be (a=0.866025f, b=0.5f, c=0.5f, d=0.866025f, tx=-4.0f, ty=2.5f)
[matrix createBoxWithScaleX:0.5f scaleY:0.5f rotation:M_PI/6.0f tx:-3.0f ty:2.0f];
// matrix will be (a=0.433013f, b=0.5f, c=0.5f, d=0.433013f, tx=-3.0f, ty=2.0f)
scaleX

The horizontal scale factor.

tx

The horizontal translation.

scaleY

The vertical scale factor.

Declared In

PXMatrix.m

deltaTransformPoint:

Returns a point transformed by this matrix, ignoring the tx and ty parameters.

- (PXPoint *)deltaTransformPoint:(PXPoint *)point

Parameters

point

The point for transformation.

Return Value

The point after transformation.

Example:

PXMatrix *matrix = [[PXMatrix alloc] initWithA:0.0f b:1.0f c:0.0f d:1.0f tx:-4.0f ty:2.5f];
// matrix will be (a=0.866025f, b=0.5f, c=0.5f, d=0.866025f, tx=-4.0f, ty=2.5f)
PXPoint *point = [[PXPoint alloc] initWithX:1.0f y:1.0f];
PXPoint *transformedPoint = [matrix deltaTransformPoint:point];
// transformedPoint will be (0.0f, 2.0f)

Declared In

PXMatrix.m

identity

Sets the values of the matrix to (a=1, b=0, c=0, d=1, tx=0, ty=0).

- (void)identity

Discussion

Example:

PXMatrix *matrix = [[PXMatrix alloc] initWithA:0.866025f b:0.5f c:0.5f d:0.866025f tx:-4.0f ty:2.5f];
// matrix will be (a=0.866025f, b=0.5f, c=0.5f, d=0.866025f, tx=-4.0f, ty=2.5f)
[matrix identity];
// matrix will be (a=1.0f, b=0.0f, c=0.0f, d=1.0f, tx=0.0f, ty=0.0f)

Declared In

PXMatrix.m

initWithA:b:c:d:tx:ty:

Creates a new matrix with values of (a, b, c, d, tx, ty).

- (id)initWithA:(float)_a b:(float)_b c:(float)_c d:(float)_d tx:(float)_tx ty:(float)_ty

Parameters

d

The value that affects the positioning of pixels along the y-axis when scaling or rotating.

b

The value that affects the positioning of pixels along the y-axis when skewing or rotating.

ty

The value that affects the positioning of pixels along the y-axis when translating.

Example:

PXMatrix *matrix = [[PXMatrix alloc] initWithA:0.866025f b:0.5f c:0.5f d:0.866025f tx:-4.0f ty:2.5f];
// matrix will be (a=0.866025f, b=0.5f, c=0.5f, d=0.866025f, tx=-4.0f, ty=2.5f)
c

The value that affects the positioning of pixels along the x-axis when skewing or rotating.

a

The value that affects the positioning of pixels along the x-axis when scaling or rotating.

tx

The value that affects the positioning of pixels along the x-axis when translating.

Declared In

PXMatrix.m

invert

Inverts the matrix. If the matrix is not invertible then the matrix is set back to identity.

- (void)invert

Discussion

Example:

PXMatrix *matrix = [[PXMatrix alloc] initWithA:1.0f b:1.0f c:0.5f d:1.0f tx:0.0f ty:0.0f];
// matrix will be (a=1.0f, b=1.0f, c=0.5f, d=1.0f, tx=0.0f, ty=0.0f)
[matrix invert];
// matrix will be (a=2.0f, b=-2.0f, c=-1.0f, d=2.0f, tx=0.0f, ty=0.0f)

Declared In

PXMatrix.m

rotate:

Rotates the matrix.

- (void)rotate:(float)angle

Parameters

angle

Angle of rotation in radians.

Example:

PXMatrix *matrix = [PXMatrix new];
// matrix will be (a=1.0f, b=0.0f, c=0.0f, d=1.0f, tx=0.0f, ty=0.0f)
[matrix rotate:M_PI/6.0f]; //30 degrees
// matrix will be (a=0.866025f, b=0.5f, c=0.5f, d=0.866025f, tx=0.0f, ty=0.0f)

Declared In

PXMatrix.m

scaleX:y:

Scales the matrix.

- (void)scaleX:(float)sx y:(float)sy

Parameters

sx

The horizontal scaling factor.

sy

The vertical scaling factor.

Example:

PXMatrix *matrix = [[PXMatrix alloc] initWithA:0.866025f b:0.5f c:0.5f d:0.866025f tx:-4.0f ty:2.5f];
// matrix will be (a=0.866025f, b=0.5f, c=0.5f, d=0.866025f, tx=-4.0f, ty=2.5f)
[matrix scaleX:0.5f y:0.5f];
// matrix will be (a=0.433012f, b=0.5f, c=0.5f, d=0.433012f, tx=-2.0f, ty=1.0f)

Declared In

PXMatrix.m

setA:b:c:d:tx:ty:

Sets the matrix values to (a, b, c, d, tx, ty).

- (void)setA:(float)_a b:(float)_b c:(float)_c d:(float)_d tx:(float)_tx ty:(float)_ty

Parameters

d

The value that affects the positioning of pixels along the y-axis when scaling or rotating.

b

The value that affects the positioning of pixels along the y-axis when skewing or rotating.

ty

The value that affects the positioning of pixels along the y-axis when translating.

Example:

PXMatrix *matrix = [[PXMatrix alloc] init];
[matrix setA:0.866025f b:0.5f c:0.5f d:0.866025f tx:-4.0f ty:2.5f];
// matrix will be (a=0.866025f, b=0.5f, c=0.5f, d=0.866025f, tx=-4.0f, ty=2.5f)
c

The value that affects the positioning of pixels along the x-axis when skewing or rotating.

a

The value that affects the positioning of pixels along the x-axis when scaling or rotating.

tx

The value that affects the positioning of pixels along the x-axis when translating.

Declared In

PXMatrix.m

transformPoint:

Returns a point transformed by this matrix.

- (PXPoint *)transformPoint:(PXPoint *)point

Parameters

point

The point for transformation.

Return Value

The point after transformation.

Example:

PXMatrix *matrix = [[PXMatrix alloc] initWithA:0.0f b:1.0f c:0.0f d:1.0f tx:-4.0f ty:2.5f];
// matrix will be (a=0.866025f, b=0.5f, c=0.5f, d=0.866025f, tx=-4.0f, ty=2.5f)
PXPoint *point = [[PXPoint alloc] initWithX:1.0f y:1.0f];
PXPoint *transformedPoint = [matrix transformPoint:point];
// transformedPoint will be (-4.0f, 4.5f)

Declared In

PXMatrix.m

translateX:y:

Translates the matrix.

- (void)translateX:(float)dx y:(float)dy

Parameters

dx

The horizontal translation.

dy

The vertical translation.

Example:

PXMatrix *matrix = [[PXMatrix alloc] initWithA:0.866025f b:0.5f c:0.5f d:0.866025f tx:-4.0f ty:2.5f];
// matrix will be (a=0.866025f, b=0.5f, c=0.5f, d=0.866025f, tx=-4.0f, ty=2.5f)
[matrix translateX:1.0f y:-0.5f];
// matrix will be (a=0.866025f, b=0.5f, c=0.5f, d=0.866025f, tx=-3.0f, ty=2.0f)

Declared In

PXMatrix.m