Structure

# CGAffineTransform

An affine transformation matrix for use in drawing 2D graphics.

## Overview

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.

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, an 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, the following equations are used 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 `translateBy(x:y:)`, `scaleBy(x:y:)`, or `rotate(by:)`, respectively. You should generally only create an affine transform if you want to reuse it later.

## Topics

### Initializers

`init(rotationAngle: CGFloat)`

Returns an affine transformation matrix constructed from a rotation value you provide.

`init(scaleX: CGFloat, y: CGFloat)`

Returns an affine transformation matrix constructed from scaling values you provide.

`init(translationX: CGFloat, y: CGFloat)`

Returns an affine transformation matrix constructed from translation values you provide.

### Instance Properties

`var isIdentity: Bool`

Checks whether an affine transform is the identity transform.

`var a: CGFloat`

The entry at position [1,1] in the matrix.

`var b: CGFloat`

The entry at position [1,2] in the matrix.

`var c: CGFloat`

The entry at position [2,1] in the matrix.

`var d: CGFloat`

The entry at position [2,2] in the matrix.

`var tx: CGFloat`

The entry at position [3,1] in the matrix.

`var ty: CGFloat`

The entry at position [3,2] in the matrix.

### Instance Methods

`func concatenating(CGAffineTransform) -> CGAffineTransform`

Returns an affine transformation matrix constructed by combining two existing affine transforms.

`func inverted() -> CGAffineTransform`

Returns an affine transformation matrix constructed by inverting an existing affine transform.

`func rotated(by: CGFloat) -> CGAffineTransform`

Returns an affine transformation matrix constructed by rotating an existing affine transform.

`func scaledBy(x: CGFloat, y: CGFloat) -> CGAffineTransform`

Returns an affine transformation matrix constructed by scaling an existing affine transform.

`func translatedBy(x: CGFloat, y: CGFloat) -> CGAffineTransform`

Returns an affine transformation matrix constructed by translating an existing affine transform.

## Relationships

### Geometric Data Types

`struct CGFloat`

The basic type for floating-point scalar values in Core Graphics and related frameworks.

`struct CGPoint`

A structure that contains a point in a two-dimensional coordinate system.

`struct CGSize`

A structure that contains width and height values.

`struct CGRect`

A structure that contains the location and dimensions of a rectangle.

`struct CGVector`

A structure that contains a two-dimensional vector.