Apply and combine affine transformations
mainAffine matrices can be used to transform coordinates or combine multiple transformations together.
Transform coordinates
Use the @ matrix multiplier operator to apply an Affine matrix to an (x, y) tuple. This returns the transformed coordinates (x', y').
Note: For versions prior to 3.0.0, use the * operator instead of @.
Combine transformations
You can multiply two Affine matrices together using the @ operator to create a single matrix that represents the combined transformation.
# Transform a point
point = (1.0, 1.0)
transformed_point = Affine.translation(1.0, 5.0) @ point
# Combine transformations
combined_matrix = Affine.translation(1.0, 5.0) @ Affine.rotation(45.0)from affine import Affine
# Apply transformation to a coordinate tuple
# Result: (2.0, 6.0)
print(Affine.translation(1.0, 5.0) @ (1.0, 1.0))
# Combine transformations
# Result: Affine(0.7071067811865476, -0.7071067811865475, 1.0, 0.7071067811865475, 0.7071067811865476, 5.0)
combined = Affine.translation(1.0, 5.0) @ Affine.rotation(45.0)