WolframLang: Apply Transform to Graphics

By Xah Lee. Date: . Last updated: .

Apply Geometric Transform to Graphics

use GeometricTransformation to apply a transformation function to Graphics Primitives

GeometricTransformation[graPrims, f]
  • applies f to graPrims.
  • graPrims should be graphics primitives, not Graphics object.

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

GeometricTransformation[graPrims, listOfTransforms]

do multiple transforms.

Example: Basic

gp = {Circle[], Rectangle[{0, 0}]};

(*  GeometricTransformation first arg should be graphics primitive or list of *)
(* result is itself, unchanged. *)
GeometricTransformation[ gp , ShearingTransform[Pi/4, {1, 0}, {0, 1}]]

(* has effect when it in inside Graphics or Graph3D *)
Graphics[
GeometricTransformation[ gp , ShearingTransform[Pi/4, {1, 0}, {0, 1}]],
Axes -> True]
wl transform graphics 2024-06-05 WJm7
wl transform graphics 2024-06-05 WJm7

Example: Using a Matrix

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

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