Framework | ApplicationServices/ApplicationServices.h |
Companion guide | |
Declared in | CGAffineTransform.h |
The CGAffineTransform
data structure represents a matrix used for affine transformations. A transformation specifies how points in one coordinate system map to points in another coordinate system. An affine transformation is a special type of mapping that preserves parallel lines in a path but does not necessarily preserve lengths or angles. Scaling, rotation, and translation are the most commonly used manipulations supported by affine transforms, but skewing is also possible.
Quartz provides functions that create, concatenate, and apply affine transformations using the CGAffineTransform
data structure. For information on how to use affine transformation functions, see Quartz 2D Programming Guide.
You typically do not need to create an affine transform directly—CGContext Reference describes functions that modify the current affine transform. If you don’t plan to reuse an affine transform, you may want to use CGContextScaleCTM
, CGContextRotateCTM
, CGContextTranslateCTM
, or CGContextConcatCTM
.
CGAffineTransformMake
CGAffineTransformMakeRotation
CGAffineTransformMakeScale
CGAffineTransformMakeTranslation
CGAffineTransformTranslate
CGAffineTransformScale
CGAffineTransformRotate
CGAffineTransformInvert
CGAffineTransformConcat
Returns an affine transformation matrix constructed by combining two existing affine transforms.
CGAffineTransform CGAffineTransformConcat ( CGAffineTransform t1, CGAffineTransform t2 );
The first affine transform.
The second affine transform. This affine transform is concatenated to the first affine transform.
A new affine transformation matrix. That is, t’ = t1*t2.
Concatenation combines two affine transformation matrices by multiplying them together. You might perform several concatenations in order to create a single affine transform that contains the cumulative effects of several transformations.
Note that matrix operations are not commutative—the order in which you concatenate matrices is important. That is, the result of multiplying matrix t1
by matrix t2
does not necessarily equal the result of multiplying matrix t2
by matrix t1
.
CGAffineTransform.h
Checks whether two affine transforms are equal.
bool CGAffineTransformEqualToTransform ( CGAffineTransform t1, CGAffineTransform t2 );
An affine transform.
An affine transform.
Returns true
if t1
and t2
are equal, false
otherwise.
CGAffineTransform.h
Returns an affine transformation matrix constructed by inverting an existing affine transform.
CGAffineTransform CGAffineTransformInvert ( CGAffineTransform t );
An existing affine transform.
A new affine transformation matrix. If the affine transform passed in parameter t
cannot be inverted, Quartz returns the affine transform unchanged.
Inversion is generally used to provide reverse transformation of points within transformed objects. Given the coordinates (x,y), which have been transformed by a given matrix to new coordinates (x’,y’), transforming the coordinates (x’,y’) by the inverse matrix produces the original coordinates (x,y).
CGAffineTransform.h
Checks whether an affine transform is the identity transform.
bool CGAffineTransformIsIdentity ( CGAffineTransform t );
The affine transform to check.
Returns true
if t
is the identity transform, false
otherwise.
CGAffineTransform.h
Returns an affine transformation matrix constructed from values you provide.
CGAffineTransform CGAffineTransformMake ( CGFloat a, CGFloat b, CGFloat c, CGFloat d, CGFloat tx, CGFloat ty );
The value at position [1,1] in the matrix.
The value at position [1,2] in the matrix.
The value at position [2,1] in the matrix.
The value at position [2,2] in the matrix.
The value at position [3,1] in the matrix.
The value at position [3,2] in the matrix.
A new affine transform matrix constructed from the values you specify.
This function creates a CGAffineTransform
structure that represents a new affine transformation matrix, which you can use (and reuse, if you want) to transform a coordinate system. The matrix takes the following form:
Because the third column is always (0,0,1)
, the CGAffineTransform
data structure returned by this function contains values for only the first two columns.
If you want only to transform an object to be drawn, it is not necessary to construct an affine transform to do so. The most direct way to transform your drawing is by calling the appropriate CGContext
function to adjust the current transformation matrix.
CGAffineTransform.h
Returns an affine transformation matrix constructed from a rotation value you provide.
CGAffineTransform CGAffineTransformMakeRotation ( CGFloat angle );
The angle, in radians, by which this matrix rotates the coordinate system axes. A positive value specifies clockwise rotation, a negative value specifies counterclockwise.
A new affine transformation matrix.
This function creates a CGAffineTransform
structure, which you can use (and reuse, if you want) to rotate a coordinate system. The matrix takes the following form:
Because the third column is always (0,0,1)
, the CGAffineTransform
data structure returned by this function contains values for only the first two columns.
These are the resulting equations that Quartz uses to apply the rotation to a point (x, y):
If you want only to rotate an object to be drawn, it is not necessary to construct an affine transform to do so. The most direct way to rotate your drawing is by calling the function CGContextRotateCTM
.
CGAffineTransform.h
Returns an affine transformation matrix constructed from scaling values you provide.
CGAffineTransform CGAffineTransformMakeScale ( CGFloat sx, CGFloat sy );
The factor by which to scale the x-axis of the coordinate system.
The factor by which to scale the y-axis of the coordinate system.
A new affine transformation matrix.
This function creates a CGAffineTransform
structure, which you can use (and reuse, if you want) to scale a coordinate system. The matrix takes the following form:
Because the third column is always (0,0,1)
, the CGAffineTransform
data structure returned by this function contains values for only the first two columns.
These are the resulting equations that Quartz uses to scale the coordinates of a point (x,y):
If you want only to scale an object to be drawn, it is not necessary to construct an affine transform to do so. The most direct way to scale your drawing is by calling the function CGContextScaleCTM
.
CGAffineTransform.h
Returns an affine transformation matrix constructed from translation values you provide.
CGAffineTransform CGAffineTransformMakeTranslation ( CGFloat tx, CGFloat ty );
The value by which to move the x-axis of the coordinate system.
The value by which to move the y-axis of the coordinate system.
A new affine transform matrix.
This function creates a CGAffineTransform
structure. which you can use (and reuse, if you want) to move a coordinate system. The matrix takes the following form:
Because the third column is always (0,0,1)
, the CGAffineTransform
data structure returned by this function contains values for only the first two columns.
These are the resulting equations Quartz uses to apply the translation to a point (x,y):
If you want only to move the location where an object is drawn, it is not necessary to construct an affine transform to do so. The most direct way to move your drawing is by calling the function CGContextTranslateCTM
.
CGAffineTransform.h
Returns an affine transformation matrix constructed by rotating an existing affine transform.
CGAffineTransform CGAffineTransformRotate ( CGAffineTransform t, CGFloat angle );
An existing affine transform.
The angle, in radians, by which to rotate the affine transform.
A new affine transformation matrix.
You use this function to create a new affine transformation matrix by adding a rotation value to an existing affine transform. The resulting structure represents a new affine transform, which you can use (and reuse, if you want) to rotate a coordinate system.
CGAffineTransform.h
Returns an affine transformation matrix constructed by scaling an existing affine transform.
CGAffineTransform CGAffineTransformScale ( CGAffineTransform t, CGFloat sx, CGFloat sy );
An existing affine transform.
The value by which to scale x values of the affine transform.
The value by which to scale y values of the affine transform.
A new affine transformation matrix.
You use this function to create a new affine transformation matrix by adding scaling values to an existing affine transform. The resulting structure represents a new affine transform, which you can use (and reuse, if you want) to scale a coordinate system.
CGAffineTransform.h
Returns an affine transformation matrix constructed by translating an existing affine transform.
CGAffineTransform CGAffineTransformTranslate ( CGAffineTransform t, CGFloat tx, CGFloat ty );
An existing affine transform.
The value by which to move x values with the affine transform.
The value by which to move y values with the affine transform.
A new affine transformation matrix.
You use this function to create a new affine transform by adding translation values to an existing affine transform. The resulting structure represents a new affine transform, which you can use (and reuse, if you want) to move a coordinate system.
CGAffineTransform.h
Returns the point resulting from an affine transformation of an existing point.
CGPoint CGPointApplyAffineTransform ( CGPoint point, CGAffineTransform t );
A point that specifies the x- and y-coordinates to transform.
The affine transform to apply.
A new point resulting from applying the specified affine transform to the existing point.
CGAffineTransform.h
Applies an affine transform to a rectangle.
CGRect CGRectApplyAffineTransform ( CGRect rect, CGAffineTransform t );
The rectangle whose corner points you want to transform.
The affine transform to apply to the rect
parameter.
The transformed rectangle.
Because affine transforms do not preserve rectangles in general, the function CGRectApplyAffineTransform
returns the smallest rectangle that contains the transformed corner points of the rect
parameter. If the affine transform t
consists solely of scaling and translation operations, then the returned rectangle coincides with the rectangle constructed from the four transformed corners.
CGAffineTransform.h
Returns the height and width resulting from a transformation of an existing height and width.
CGSize CGSizeApplyAffineTransform ( CGSize size, CGAffineTransform t );
A size that specifies the height and width to transform.
The affine transform to apply.
A new size resulting from applying the specified affine transform to the existing size.
CGAffineTransform.h
A structure for holding an affine transformation matrix.
struct CGAffineTransform { CGFloat a; CGFloat b; CGFloat c; CGFloat d; CGFloat tx; CGFloat ty; }; typedef struct CGAffineTransform CGAffineTransform;
a
The entry at position [1,1] in the matrix.
b
The entry at position [1,2] in the matrix.
c
The entry at position [2,1] in the matrix.
d
The entry at position [2,2] in the matrix.
tx
The entry at position [3,1] in the matrix.
ty
The entry at position [3,2] in the matrix.
In Quartz 2D, an affine transformation matrix is used to rotate, scale, translate, or skew the objects you draw in a graphics context. The CGAffineTransform
type provides functions for creating, concatenating, and applying affine transformations.
In Quartz, affine transforms are represented by a 3 by 3 matrix:
Because the third column is always (0,0,1)
, the CGAffineTransform
data structure contains values for only the first two columns.
Conceptually, a Quartz affine transform multiplies a row vector representing each point (x,y) in your drawing by this matrix, producing a vector that represents the corresponding point (x’,y’):
Given the 3 by 3 matrix, Quartz uses the following equations to transform a point (x, y) in one coordinate system into a resultant point (x’,y’) in another coordinate system.
The matrix thereby “links” two coordinate systems—it specifies how points in one coordinate system map to points in another.
Note that you do not typically need to create affine transforms directly. If you want only to draw an object that is scaled or rotated, for example, it is not necessary to construct an affine transform to do so. The most direct way to manipulate your drawing—whether by movement, scaling, or rotation—is to call the functions CGContextTranslateCTM
, CGContextScaleCTM
, or CGContextRotateCTM
, respectively. You should generally only create an affine transform if you want to reuse it later.
CGAffineTransform.h
The identity transform.
const CGAffineTransform CGAffineTransformIdentity;
CGAffineTransformIdentity
The identity transform:
Available in Mac OS X v10.0 and later.
Declared in CGAffineTransform.h
.
CGAffineTransform.h
© 2003, 2008 Apple Inc. All Rights Reserved. (Last updated: 2008-04-08)