PXMatrix Class Reference
| 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
-
aThe value that affects the positioning of pixels along the x-axis when scaling or rotating the matrix.
property -
bThe value that affects the positioning of pixels along the y-axis when skewing or rotating the matrix.
property -
cThe value that affects the positioning of pixels along the x-axis when skewing or rotating the matrix.
property -
dThe value that affects the positioning of pixels along the y-axis when scaling or rotating the matrix.
property -
txThe value that affects the positioning of pixels along the x-axis when translating the matrix.
property -
tyThe 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.
-
– identitySets the values of the matrix to (a=1, b=0, c=0, d=1, tx=0, ty=0).
-
– invertInverts 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).
-
+ identityMatrixCreates 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 aDeclared In
PXMatrix.hb
The value that affects the positioning of pixels along the y-axis when skewing or rotating the matrix.
@property (nonatomic) float bDeclared In
PXMatrix.hc
The value that affects the positioning of pixels along the x-axis when skewing or rotating the matrix.
@property (nonatomic) float cDeclared In
PXMatrix.hd
The value that affects the positioning of pixels along the y-axis when scaling or rotating the matrix.
@property (nonatomic) float dDeclared In
PXMatrix.hClass 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 *)identityMatrixDiscussion
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.mmatrixWithA: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)tyParameters
- 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.mInstance Methods
concat:
Concatenates the specified matrix with this matrix, this is the same as multiplying the specified matrix with this matrix.
- (void)concat:(PXMatrix *)mParameters
- 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.mcreateBoxWithScaleX: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)_tyParameters
- 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.mdeltaTransformPoint:
Returns a point transformed by this matrix, ignoring the tx and ty parameters.
- (PXPoint *)deltaTransformPoint:(PXPoint *)pointParameters
- 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.midentity
Sets the values of the matrix to (a=1, b=0, c=0, d=1, tx=0, ty=0).
- (void)identityDiscussion
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.minitWithA: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)_tyParameters
- 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.minvert
Inverts the matrix. If the matrix is not invertible then the matrix is set back to identity.
- (void)invertDiscussion
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.mrotate:
Rotates the matrix.
- (void)rotate:(float)angleParameters
- 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.mscaleX:y:
Scales the matrix.
- (void)scaleX:(float)sx y:(float)syParameters
- 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.msetA: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)_tyParameters
- 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.mtransformPoint:
Returns a point transformed by this matrix.
- (PXPoint *)transformPoint:(PXPoint *)pointParameters
- 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.mtranslateX:y:
Translates the matrix.
- (void)translateX:(float)dx y:(float)dyParameters
- 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