How do you plot a closed curve in Julia? For instance using Plots.jl
. I would like to draw an ellipse into a 3-dimensional plot.
Maybe these give some ideas
https://lazarusa.github.io/Webpage/codeJuliaMakie.html#collapse3dplots
2 Likes
With Plots.jl gr() you can draw parametric curves as follows:
using Rotations, Plots; gr()
M(u) = [a/2*cos(u), b/2*sin(u), 0] # ellipse in X-Y plane
RM(u) = RotXYZ(α,β,γ) * M(u) .+ C # rotated + shifted ellipse in 3D
C = [1, 1, 2] # center of ellipse
α, β, γ = π/4, 0, π/3 # Euler angles
a, b = 5.0, 2.0 # ellipse principal axes
u = LinRange(0, 2π, 72)
xs, ys, zs = [[p[i] for p in RM.(u)] for i in 1:3]
p = plot(xs,ys,zs, lc=:blue, lw=3, ratio=1, legend=false, xlabel="X",ylabel="Y",zlabel="Z")
Can also add some X-Y-Z projections to help 3D visualization:
# project curve to X-Y-Z planes
xl, yl, zl = xlims(p), ylims(p), zlims(p)
plot!(xs, ys, zl[1].+ 0*zs, lw=1, lc=:lightgray)
plot!(xs, yl[2] .+ 0*ys, zs, lw=1, lc=:lightgray)
plot!(xl[1] .+ 0*xs, ys, zs, lw=1, lc=:lightgray)
plot!(xs,ys,zs, lc=:blue,lw=3,xlims=xl,ylims=yl,zlims=zl) # plot again to front
4 Likes
Can you post the code you used to draw the x,y,z projections?
1 Like
@e3c6, as requested, see above.
NB: last drawing using Euler angles: α, β, γ = -π/6, -π/6, -π/2
2 Likes