@@ -20,6 +20,7 @@ using GeoJSON # to load some data
2020# Packages for coordinate transformation and projection
2121import CoordinateTransformations
2222import Proj
23+ import Rotations
2324# Plotting
2425using CairoMakie
2526using GeoMakie
@@ -113,16 +114,13 @@ plot!(polygon1)
113114fig
114115````
115116
116- We can also rotate a polygon with the same ` transform ` function. A ` LinearMap `
117- rotates around the origin.
117+ We can also rotate a polygon with the same ` transform ` function. Here we use a
118+ 2D rotation from ` Rotations.jl ` , which rotates around the origin.
118119
119120```` @example creating_geometry
120121theta = π / 4
121- rotation = CoordinateTransformations.LinearMap([
122- cos(theta) -sin(theta)
123- sin(theta) cos(theta)
124- ]);
125- polygon1_rotated_origin = GO.transform(rotation, polygon1);
122+ rotation = Rotations.Angle2d(theta);
123+ polygon1_rotated_origin = GO.transform(p -> rotation * p, polygon1);
126124
127125fig_rotation = Figure()
128126ax_origin = Axis(fig_rotation[1, 1]; title = "Rotate around the origin", aspect = DataAspect())
@@ -131,15 +129,15 @@ poly!(ax_origin, polygon1_rotated_origin; color = (:orange, 0.35), strokecolor =
131129fig_rotation
132130````
133131
134- To rotate around a polygon's centroid instead, compose the rotation with
135- translations before and after it .
132+ To rotate around a polygon's centroid instead, rotate each point relative to
133+ the centroid and then shift it back .
136134
137135```` @example creating_geometry
138136polygon1_centroid = GO.centroid(polygon1)
139- rotation_about_centroid = CoordinateTransformations.Translation(polygon1_centroid...) ∘
140- rotation ∘
141- CoordinateTransformations.Translation((-).(polygon1_centroid)...)
142- polygon1_rotated_centroid = GO.transform(rotation_about_centroid, polygon1 );
137+ polygon1_rotated_centroid = GO.transform(
138+ p -> rotation * (p .- polygon1_centroid) .+ polygon1_centroid,
139+ polygon1,
140+ );
143141
144142ax_centroid = Axis(fig_rotation[1, 2]; title = "Rotate around the centroid", aspect = DataAspect())
145143poly!(ax_centroid, polygon1; color = (:steelblue, 0.5), strokecolor = :steelblue)
0 commit comments