-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update Project.toml for RecipesBase * add RotationsRecipesBaseExt * update plotting recipe for `Rotation{3}` * fix ext dependency * update for Julia v1.6 * add support recipe for `Rotation{2}` * add tests for plotting recipe * update axis color
- Loading branch information
Showing
6 changed files
with
127 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
perf/benchmarkparams.json | ||
Manifest.toml | ||
docs/build | ||
/test/out_plot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
module RotationsRecipesBaseExt | ||
|
||
using RecipesBase | ||
using Rotations | ||
using StaticArrays | ||
|
||
@recipe function f(R::Rotation{2}; origin=SVector(0,0), boxsize=0.2, axissize=1.0) | ||
l = boxsize | ||
L = axissize | ||
e₁ = R[:,1] | ||
e₂ = R[:,2] | ||
ox, oy = origin | ||
ps = vec([SVector(ox,oy)+R*SVector(x,y) for x in (-l,l), y in (-l,l)]) | ||
xs = getindex.(ps,1) | ||
ys = getindex.(ps,2) | ||
@series begin | ||
primary := false | ||
color := :red1 | ||
[e₁[1]*l+ox,e₁[1]*L+ox],[e₁[2]*l+oy,e₁[2]*L+oy] | ||
end | ||
@series begin | ||
primary := false | ||
color := :green1 | ||
[e₂[1]*l+ox,e₂[1]*L+ox],[e₂[2]*l+oy,e₂[2]*L+oy] | ||
end | ||
fill := true | ||
delete!(plotattributes, :origin) | ||
delete!(plotattributes, :boxsize) | ||
delete!(plotattributes, :axissize) | ||
xs[[1,3,4,2,1]], ys[[1,3,4,2,1]] | ||
end | ||
|
||
@recipe function f(R::Rotation{3}; origin=SVector(0,0,0), boxsize=0.2, axissize=1.0) | ||
l = boxsize | ||
L = axissize | ||
e₁ = R[:,1] | ||
e₂ = R[:,2] | ||
e₃ = R[:,3] | ||
ox, oy, oz = origin | ||
ps = vec([SVector(ox,oy,oz)+R*SVector(x,y,z) for x in (-l,l), y in (-l,l), z in (-l,l)]) | ||
xs = getindex.(ps,1) | ||
ys = getindex.(ps,2) | ||
zs = getindex.(ps,3) | ||
@series begin | ||
primary := false | ||
color := :red1 | ||
[e₁[1]*l+ox,e₁[1]*L+ox],[e₁[2]*l+oy,e₁[2]*L+oy],[e₁[3]*l+oz,e₁[3]*L+oz] | ||
end | ||
@series begin | ||
primary := false | ||
color := :green1 | ||
[e₂[1]*l+ox,e₂[1]*L+ox],[e₂[2]*l+oy,e₂[2]*L+oy],[e₂[3]*l+oz,e₂[3]*L+oz] | ||
end | ||
@series begin | ||
primary := false | ||
color := :blue1 | ||
[e₃[1]*l+ox,e₃[1]*L+ox],[e₃[2]*l+oy,e₃[2]*L+oy],[e₃[3]*l+oz,e₃[3]*L+oz] | ||
end | ||
seriestype := :mesh3d | ||
connections := ( | ||
# Somehow 0-based indexing | ||
# https://docs.juliaplots.org/latest/gallery/gr/generated/gr-ref047/ | ||
[1-1,1-1,1-1,1-1,1-1,1-1,8-1,8-1,8-1,8-1,8-1,8-1,], | ||
[2-1,6-1,4-1,3-1,7-1,5-1,4-1,3-1,7-1,5-1,6-1,2-1,], | ||
[6-1,5-1,2-1,4-1,3-1,7-1,3-1,7-1,5-1,6-1,2-1,4-1,], | ||
) | ||
# This connections can be 1-based indexing, but this throws an error on PythonPlot. | ||
# https://discourse.julialang.org/t/how-to-plot-a-cube-in-3d-in-plots-jl/86919/2?u=hyrodium | ||
# connections := [(1,2,6),(1,6,5),(1,4,2),(1,3,4),(1,7,3),(1,5,7),(8,4,3),(8,3,7),(8,7,5),(8,5,6),(8,6,2),(8,2,4)] | ||
delete!(plotattributes, :origin) | ||
delete!(plotattributes, :boxsize) | ||
delete!(plotattributes, :axissize) | ||
xs,ys,zs | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
@testset "plot" begin | ||
dir_out = joinpath(@__DIR__, "out_plot") | ||
rm(dir_out; force=true, recursive=true) | ||
mkpath(dir_out) | ||
|
||
@testset "2d" begin | ||
pl = plot(Angle2d(0.2); aspectratio=1) | ||
plot!(pl, Angle2d(0.3); aspectratio=1) | ||
|
||
path_img = joinpath(dir_out, "2d.png") | ||
@test !isfile(path_img) | ||
savefig(pl, path_img) | ||
@test isfile(path_img) | ||
end | ||
|
||
@testset "3d" begin | ||
N = 12 | ||
Random.seed!(42) | ||
R1 = rand(QuatRotation) | ||
R2 = rand(QuatRotation) | ||
pl = plot(R1; linewidth=3, label="R1") | ||
plot!(pl, R2; linewidth=3, label="R2", origin=(1,0,0)) | ||
for i in 2:N-1 | ||
t = i/N | ||
plot!(pl, slerp(R1,R2,t); linewidth=3, label=nothing, origin=(t,0,0), boxsize=0.0, axissize=3/4) | ||
end | ||
|
||
path_img = joinpath(dir_out, "3d.png") | ||
@test !isfile(path_img) | ||
savefig(pl, path_img) | ||
@test isfile(path_img) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters