Skip to content

Commit 9c16858

Browse files
committed
Replace LinearMap with Angle2d in tutorial
Signed-off-by: Avnish Jaltare <avnishjaltare8@gmail.com>
1 parent d54972c commit 9c16858

2 files changed

Lines changed: 12 additions & 13 deletions

File tree

docs/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ NaturalEarth = "436b0209-26ab-4e65-94a9-6526d86fea76"
4242
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
4343
Proj = "c94c279d-25a6-4763-9509-64d165bea63e"
4444
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
45+
Rotations = "6038ab10-8711-5258-84ad-4b1120ba62dc"
4546
Shapefile = "8e980c4a-a4fe-5da2-b3a7-4b4b0353a2f4"
4647
SortTileRecursiveTree = "746ee33f-1797-42c2-866d-db2fce69d14d"
4748
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

docs/src/tutorials/creating_geometry.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ using GeoJSON # to load some data
2020
# Packages for coordinate transformation and projection
2121
import CoordinateTransformations
2222
import Proj
23+
import Rotations
2324
# Plotting
2425
using CairoMakie
2526
using GeoMakie
@@ -113,16 +114,13 @@ plot!(polygon1)
113114
fig
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
120121
theta = π / 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
127125
fig_rotation = Figure()
128126
ax_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 =
131129
fig_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
138136
polygon1_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
144142
ax_centroid = Axis(fig_rotation[1, 2]; title = "Rotate around the centroid", aspect = DataAspect())
145143
poly!(ax_centroid, polygon1; color = (:steelblue, 0.5), strokecolor = :steelblue)

0 commit comments

Comments
 (0)