Wolfram: Apply Transform to Graphics

By Xah Lee. Date: . Last updated: .

Apply Geometric Transform to Graphics

GeometricTransformation[graPrims, f]

applies f to graPrims.

graPrims should be Graphics Primitives , not Graphics object.

f is typically TransformationFunction[data]. 〔see Geometric Transformation Functions

It can be a matrix.

It can be a {matrix, vector} , where the vector is used for translation. 〔see Transformation Matrix

GeometricTransformation[angs] return itself unchanged. It display effect when it is inside Graphics or Graphics3D.

GeometricTransformation[graPrims, listOfTransforms]

do copy of multiple transformations.

Example: Basic

wl transform graphics 2024-10-17 013902
wl transform graphics 2024-10-17 013902
(*  GeometricTransformation first arg should be graphics primitive or list of *)

GeometricTransformation[ {Circle[], Rectangle[{0, 0}]} , RotationTransform[ 10 Degree ] ]
(* result is itself, unchanged. *)

(* has effect when it in inside Graphics or Graph3D *)
Graphics[
GeometricTransformation[
{Circle[], Rectangle[{0, 0}]} ,
RotationTransform[ 10 Degree ]
],
Axes -> True]

Example: Using a Matrix

WolframLang geo transform 2024-06-01 2cR2
WolframLang geo transform 2024-06-01 2cR2
(* rotate a rectangle *)
Graphics[
GeometricTransformation[
{Rectangle[{0, 0}]} ,
RotationMatrix[ 10 Degree ]
],
Axes -> True
]

Example: Using a Matrix and a Vector

(* transform by a matrix, and translate by a vector *)
Graphics[
GeometricTransformation[
{Rectangle[{0, 0}]} ,
{RotationMatrix[ 10 Degree ], {1,1}}
],
Axes -> True
]
WolframLang transform 2024-06-01 BTXD
WolframLang transform 2024-06-01 BTXD

Example: Error If Not on Graphics Primitive

(* if GeometricTransformation's args is Graphics[...], no transform is done. *)
result =
GeometricTransformation[
Graphics[{Rectangle[{0, 0}]}],
RotationTransform[ 10 Degree ]
]

(* if you show result inside Graphics[...], it's an error. *)
Show[ result ]
WolframLang geo transform error 2024-06-02
WolframLang geo transform error 2024-06-02

WolframLang, Graphics Programing