Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [1.21.1] - 2026-09-30
- Fix corner case in 3D slice plotting
- Use special rotation for `x`-`y` rotations in 3D: keep `z` original, map it to `y`

## [1.21.0] - 2026-09-16
- Replace plottertypes by Singleton

Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "GridVisualize"
uuid = "5eed8a63-0fb0-45eb-886d-8d5a387d12b8"
version = "1.21"
version = "1.21.1"
authors = ["Juergen Fuhrmann <juergen.fuhrmann@wias-berlin.de>", "Patrick Jaap <patrick.jaap@wias-berlin.de>"]

[deps]
Expand Down
16 changes: 14 additions & 2 deletions src/slice_plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ function compute_3d_z_rotation_matrix(target_vector)
β = acos(t[3] / cos(α))
end

# check t[1]:
if cos(α) * sin(β) ≉ t[1]
β = -β
end

return R_y(β) * R_x(α)
end

Expand Down Expand Up @@ -216,8 +221,8 @@ function slice_plot!(ctx, ::Type{Val{3}}, grid, values)

a::Float64, b::Float64, c::Float64, _ = plane

# transformation matrix
if (a, b, c) == (1.0, 0.0, 0.0)

if (a, b, c) == (1.0, 0.0, 0.0) # simple axis directions
rotation_matrix = @SArray [
0.0 0.0 1.0
1.0 0.0 0.0
Expand All @@ -235,6 +240,13 @@ function slice_plot!(ctx, ::Type{Val{3}}, grid, values)
0.0 1.0 0.0
0.0 0.0 1.0
]
elseif c == 0 # special case for c = 0: keep z-axis original
M = compute_2d_rotation_matrix([a, b])
rotation_matrix = @SArray [
M[1, 1] 0.0 M[1, 2]
M[2, 1] 0.0 M[2, 2]
0.0 1.0 0.0
]
else
rotation_matrix = compute_3d_z_rotation_matrix([a, b, c])
end
Expand Down
6 changes: 5 additions & 1 deletion test/test_slice_plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,18 @@ end
@test abs(η ⋅ t) < 1.0e-15
@test abs(ξ ⋅ t) < 1.0e-15

# tricky case
t = [-1.0, 1.0, 0.0] / sqrt(2)
R = GridVisualize.compute_3d_z_rotation_matrix(t)
@test R[:, 3] ≈ t

# corner case I: only one axis rotation necessary
t = [1, 0, 0]
@test GridVisualize.compute_3d_z_rotation_matrix(t) ≈ [0 0 1; 0 1 0; -1 0 0]

# corner case II: only one axis rotation necessary
t = [0, 1, 0]
@test GridVisualize.compute_3d_z_rotation_matrix(t) ≈ [1 0 0; 0 0 1; 0 -1 0]

end


Expand Down
Loading