|
| 1 | +module RotationsRecipesBaseExt |
| 2 | + |
| 3 | +using RecipesBase |
| 4 | +using Rotations |
| 5 | +using StaticArrays |
| 6 | + |
| 7 | +@recipe function f(R::Rotation{2}; origin=SVector(0,0), boxsize=0.2, axissize=1.0) |
| 8 | + l = boxsize |
| 9 | + L = axissize |
| 10 | + e₁ = R[:,1] |
| 11 | + e₂ = R[:,2] |
| 12 | + ox, oy = origin |
| 13 | + ps = vec([SVector(ox,oy)+R*SVector(x,y) for x in (-l,l), y in (-l,l)]) |
| 14 | + xs = getindex.(ps,1) |
| 15 | + ys = getindex.(ps,2) |
| 16 | + @series begin |
| 17 | + primary := false |
| 18 | + color := :red1 |
| 19 | + [e₁[1]*l+ox,e₁[1]*L+ox],[e₁[2]*l+oy,e₁[2]*L+oy] |
| 20 | + end |
| 21 | + @series begin |
| 22 | + primary := false |
| 23 | + color := :green1 |
| 24 | + [e₂[1]*l+ox,e₂[1]*L+ox],[e₂[2]*l+oy,e₂[2]*L+oy] |
| 25 | + end |
| 26 | + fill := true |
| 27 | + delete!(plotattributes, :origin) |
| 28 | + delete!(plotattributes, :boxsize) |
| 29 | + delete!(plotattributes, :axissize) |
| 30 | + xs[[1,3,4,2,1]], ys[[1,3,4,2,1]] |
| 31 | +end |
| 32 | + |
| 33 | +@recipe function f(R::Rotation{3}; origin=SVector(0,0,0), boxsize=0.2, axissize=1.0) |
| 34 | + l = boxsize |
| 35 | + L = axissize |
| 36 | + e₁ = R[:,1] |
| 37 | + e₂ = R[:,2] |
| 38 | + e₃ = R[:,3] |
| 39 | + ox, oy, oz = origin |
| 40 | + ps = vec([SVector(ox,oy,oz)+R*SVector(x,y,z) for x in (-l,l), y in (-l,l), z in (-l,l)]) |
| 41 | + xs = getindex.(ps,1) |
| 42 | + ys = getindex.(ps,2) |
| 43 | + zs = getindex.(ps,3) |
| 44 | + @series begin |
| 45 | + primary := false |
| 46 | + color := :red1 |
| 47 | + [e₁[1]*l+ox,e₁[1]*L+ox],[e₁[2]*l+oy,e₁[2]*L+oy],[e₁[3]*l+oz,e₁[3]*L+oz] |
| 48 | + end |
| 49 | + @series begin |
| 50 | + primary := false |
| 51 | + color := :green1 |
| 52 | + [e₂[1]*l+ox,e₂[1]*L+ox],[e₂[2]*l+oy,e₂[2]*L+oy],[e₂[3]*l+oz,e₂[3]*L+oz] |
| 53 | + end |
| 54 | + @series begin |
| 55 | + primary := false |
| 56 | + color := :blue1 |
| 57 | + [e₃[1]*l+ox,e₃[1]*L+ox],[e₃[2]*l+oy,e₃[2]*L+oy],[e₃[3]*l+oz,e₃[3]*L+oz] |
| 58 | + end |
| 59 | + seriestype := :mesh3d |
| 60 | + connections := ( |
| 61 | + # Somehow 0-based indexing |
| 62 | + # https://docs.juliaplots.org/latest/gallery/gr/generated/gr-ref047/ |
| 63 | + [1-1,1-1,1-1,1-1,1-1,1-1,8-1,8-1,8-1,8-1,8-1,8-1,], |
| 64 | + [2-1,6-1,4-1,3-1,7-1,5-1,4-1,3-1,7-1,5-1,6-1,2-1,], |
| 65 | + [6-1,5-1,2-1,4-1,3-1,7-1,3-1,7-1,5-1,6-1,2-1,4-1,], |
| 66 | + ) |
| 67 | + # This connections can be 1-based indexing, but this throws an error on PythonPlot. |
| 68 | + # https://discourse.julialang.org/t/how-to-plot-a-cube-in-3d-in-plots-jl/86919/2?u=hyrodium |
| 69 | + # 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)] |
| 70 | + delete!(plotattributes, :origin) |
| 71 | + delete!(plotattributes, :boxsize) |
| 72 | + delete!(plotattributes, :axissize) |
| 73 | + xs,ys,zs |
| 74 | +end |
| 75 | + |
| 76 | +end |
0 commit comments