gives a TransformationFunction that represents an affine transform that maps r to m.r.
AffineTransform[{m,v}]
gives an affine transform that maps r to m.r+v.
AffineTransform
gives a TransformationFunction that represents an affine transform that maps r to m.r.
AffineTransform[{m,v}]
gives an affine transform that maps r to m.r+v.
Details
- AffineTransform gives a TransformationFunction that can be applied to vectors.
- For ordinary affine transforms in
dimensions, m is an
×
matrix. - AffineTransform in general supports
×
matrices for transformations in
dimensions.
Examples
open all close allBasic Examples (2)
A general affine transformation:
t = AffineTransform[{{{Subscript[a, 1, 1], Subscript[a, 1, 2]}, {Subscript[a, 2, 1], Subscript[a, 2, 2]}}, {Subscript[b, 1], Subscript[b, 2]}}]t[{x, y}]tr = AffineTransform[RotationMatrix[θ]]tr[{x, y}]tt = AffineTransform[{IdentityMatrix[2], {Subscript[b, 1], Subscript[b, 2]}}]tt[{x, y}]Scope (3)
Affine transform in four dimensions:
t = AffineTransform[{DiagonalMatrix[{1, 1, 1, 2}], {x0, y0, z0, w0}}]t[{x, y, z, w}]InverseFunction[t]InverseFunction[t][{x, y, z, w}]Transformation applied to a 2D shape:
gr = {Rectangle[], AbsolutePointSize[10], Opacity[1], {Magenta, Point[{0, 0}]}, {Green, Point[{1, 1}]}};Graphics[{{Opacity[.35], Blue, gr}, GeometricTransformation[{Opacity[.85], Red, gr}, AffineTransform[{{.8, .5}, {0, .8}}]]}]Transformation applied to a 3D shape:
gr = {Cuboid[], AbsolutePointSize[10], Opacity[1], {Magenta, Point[{0, 0, 0}]}, {Green, Point[{1, 1, 1}]}};Graphics3D[{{Opacity[.35], Blue, gr}, GeometricTransformation[{Opacity[.85], Red, gr}, AffineTransform[{{.8, .5, .5}, {0, .8, .5}, {0, 0, .8}}]]}, Boxed -> False]Applications (5)
Iterated Function Systems (3)
Define an iterated function system (IFS) and iterate it on point sets, by computing
in each iteration:
IFS[{T__TransformationFunction}][pl_List] := Join@@Comap[{T}, pl]IFSPlot[f_IFS, pts_, n_Integer] := Graphics[{PointSize[Tiny], Point[Nest[f, pts, n]]}]SierpinskiGasket = With[{𝒟 = DiagonalMatrix[{1, 1} / 2]}, IFS[{AffineTransform[{𝒟}], AffineTransform[{𝒟, {1 / 2, 0}}],
AffineTransform[{𝒟, {0.25, 0.433}}]}]];IFSPlot[N@SierpinskiGasket, RandomReal[1, {100, 2}], 4]SierpinskiCarpet = With[{𝒟 = DiagonalMatrix[{1, 1} / 3]}, IFS[{AffineTransform[{𝒟} ], AffineTransform[{𝒟, {0, 1 / 3}}], AffineTransform[{𝒟, {0, 2 / 3}}], AffineTransform[{𝒟, {1 / 3, 0}}], AffineTransform[{𝒟, {1 / 3, 2 / 3}}], AffineTransform[{𝒟, {2 / 3, 0}}], AffineTransform[{𝒟, {2 / 3, 1 / 3}}],
AffineTransform[{𝒟, {2 / 3, 2 / 3}}]}]];IFSPlot[N@SierpinskiCarpet, RandomReal[1, {100, 2}], 4]HeighwayDragon = IFS[{AffineTransform[{{{1 / 2, -1 / 2}, {1 / 2, 1 / 2}}}], AffineTransform[{{{-1 / 2, -1 / 2}, {1 / 2, -1 / 2}}, {1, 0}}]}];IFSPlot[N@HeighwayDragon, RandomReal[1, {100, 2}], 12]Compute an iterated function system's (IFS) fixed points efficiently by randomly picking subparts of point sets:
RandomIFS[IFS[{T__TransformationFunction}], m_][pl_List] :=
Apply[Join, Comap[{T}, RandomChoice[pl, m]]]IFSPlot[f_RandomIFS, pts_, n_Integer] := Graphics[{PointSize[Tiny], Point[Nest[f, pts, n]]}]SierpinskiGasket = With[{𝒟 = DiagonalMatrix[{1, 1} / 2]}, IFS[{AffineTransform[{𝒟}], AffineTransform[{𝒟, {1 / 2, 0}}],
AffineTransform[{𝒟, {0.25, 0.433}}]}]];IFSPlot[RandomIFS[N@SierpinskiGasket, 10^3], RandomReal[1, {10 ^ 3, 2}], 12]SierpinskiCarpet = With[{𝒟 = DiagonalMatrix[{1, 1} / 3]}, IFS[{AffineTransform[{𝒟} ], AffineTransform[{𝒟, {0, 1 / 3}}], AffineTransform[{𝒟, {0, 2 / 3}}], AffineTransform[{𝒟, {1 / 3, 0}}], AffineTransform[{𝒟, {1 / 3, 2 / 3}}], AffineTransform[{𝒟, {2 / 3, 0}}], AffineTransform[{𝒟, {2 / 3, 1 / 3}}],
AffineTransform[{𝒟, {2 / 3, 2 / 3}}]}]];IFSPlot[RandomIFS[N@SierpinskiCarpet, 10 ^ 3], RandomReal[1, {1000, 2}], 20]HeighwayDragon = IFS[{AffineTransform[{{{1 / 2, -1 / 2}, {1 / 2, 1 / 2}}}], AffineTransform[{{{-1 / 2, -1 / 2}, {1 / 2, -1 / 2}}, {1, 0}}]}];IFSPlot[RandomIFS[N@HeighwayDragon, 10 ^ 4], RandomReal[1, {10 ^ 4, 2}], 12]Hedgehog = With[{a = (1 + 1 / 3) / 2, b = (1 - 1 / 3) / 2}, IFS[{ScalingTransform[{1, 1, 1} / 3], ScalingTransform[{b, b, b}].TranslationTransform[{a, a, a}], ScalingTransform[{b, b, b}].TranslationTransform[{a, a, -a}], ScalingTransform[{b, b, b}].TranslationTransform[{a, -a, a}], ScalingTransform[{b, b, b}].TranslationTransform[{a, -a, -a}], ScalingTransform[{b, b, b}].TranslationTransform[{-a, a, a}], ScalingTransform[{b, b, b}].TranslationTransform[{-a, a, -a}],
ScalingTransform[{b, b, b}].TranslationTransform[{-a, -a, a}],
ScalingTransform[{b, b, b}].TranslationTransform[{-a, -a, -a}],
ScalingTransform[{b, b, b}].TranslationTransform[{-a, -a, -a}]}]];Graphics3D[ {PointSize[Tiny], Point[Nest[RandomIFS[N@Hedgehog, 10 ^ 4], RandomReal[1, {100, 3}], 3]]}]Compute an iterated function system applied to graphics primitives:
TransformIFS[g_, IFS[l_List]] :=
Module[{prim = First[g], h = Head[g]},
t = Table[GeometricTransformation[prim, l[[i]]], {i, Length[l]}];h[t]];TransformIFS[g_, ifs_IFS, 0] := g;
TransformIFS[g_, ifs_IFS, 1] := TransformIFS[g, ifs];
TransformIFS[g_, ifs_IFS, n_Integer ? Positive] :=
TransformIFS[TransformIFS[g, ifs], ifs, n - 1];SierpinskiGasket = With[{𝒟 = DiagonalMatrix[{1, 1} / 2]}, IFS[{AffineTransform[{𝒟}], AffineTransform[{𝒟, {1 / 2, 0}}],
AffineTransform[{𝒟, {0.25, 0.433}}]}]];Table[TransformIFS[Graphics[Rectangle[]], SierpinskiGasket, n], {n, 0, 5}]SierpinskiCarpet = With[{𝒟 = DiagonalMatrix[{1, 1} / 3]}, IFS[{AffineTransform[{𝒟} ], AffineTransform[{𝒟, {0, 1 / 3}}], AffineTransform[{𝒟, {0, 2 / 3}}], AffineTransform[{𝒟, {1 / 3, 0}}], AffineTransform[{𝒟, {1 / 3, 2 / 3}}], AffineTransform[{𝒟, {2 / 3, 0}}], AffineTransform[{𝒟, {2 / 3, 1 / 3}}],
AffineTransform[{𝒟, {2 / 3, 2 / 3}}]}]];Table[TransformIFS[Graphics[Rectangle[]], SierpinskiCarpet, n], {n, 0, 3}]Hedgehog = With[{a = (1 + 1 / 3) / 2, b = (1 - 1 / 3) / 2}, IFS[{ScalingTransform[{1, 1, 1} / 3], ScalingTransform[{b, b, b}].TranslationTransform[{a, a, a}], ScalingTransform[{b, b, b}].TranslationTransform[{a, a, -a}], ScalingTransform[{b, b, b}].TranslationTransform[{a, -a, a}], ScalingTransform[{b, b, b}].TranslationTransform[{a, -a, -a}], ScalingTransform[{b, b, b}].TranslationTransform[{-a, a, a}], ScalingTransform[{b, b, b}].TranslationTransform[{-a, a, -a}],
ScalingTransform[{b, b, b}].TranslationTransform[{-a, -a, a}],
ScalingTransform[{b, b, b}].TranslationTransform[{-a, -a, -a}],
ScalingTransform[{b, b, b}].TranslationTransform[{-a, -a, -a}]}]];Table[TransformIFS[Graphics3D[Cuboid[]], Hedgehog, n], {n, 0, 3}]Image Transformations (2)
Use an AffineTransform to rotate an image:
ImageTransformation[[image], AffineTransform[(| | |
| ----------- | ---------- |
| Cos[π / 8] | Sin[π / 8] |
| -Sin[π / 8] | Cos[π / 8] |)]]Affine transform of a 3D image with no translation:
ImageTransformation[[image], AffineTransform[(| | | |
| - | --- | - |
| 1 | 0.5 | 0 |
| 0 | 1 | 0 |
| 0 | 0 | 1 |)]]Properties & Relations (3)
Many other geometric transformations are a special case of affine transform:
Composition[TranslationTransform[{x0, y0}], RotationTransform[a]] == AffineTransform[{{{Cos[a], -Sin[a]}, {Sin[a], Cos[a]}}, {x0, y0}}]In turn, an affine transformation is a special case of a linear-fractional transformation:
{m, v} = {Array[a, {3, 3}], {x, y, z}};AffineTransform[{m, v}] == LinearFractionalTransform[{m, v, {0, 0, 0}, 1}]The composition of affine transforms is an affine transform:
{m1, v1} = {Array[a1, {2, 2}], {x[1], y[1]}};{m2, v2} = {Array[a2, {2, 2}], {x[2], y[2]}};Composition[AffineTransform[{m1, v1}], AffineTransform[{m2, v2}]] == AffineTransform[{m1.m2, m1.v2 + v1}]Related Guides
History
Text
Wolfram Research (2007), AffineTransform, Wolfram Language function, https://reference.wolfram.com/language/ref/AffineTransform.html.
CMS
Wolfram Language. 2007. "AffineTransform." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/AffineTransform.html.
APA
Wolfram Language. (2007). AffineTransform. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/AffineTransform.html
BibTeX
@misc{reference.wolfram_2026_affinetransform, author="Wolfram Research", title="{AffineTransform}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/AffineTransform.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_affinetransform, organization={Wolfram Research}, title={AffineTransform}, year={2007}, url={https://reference.wolfram.com/language/ref/AffineTransform.html}, note=[Accessed: 12-June-2026]}