3D rigid body energy level - from Matlab to Julia

With Oscar’s solution, I think the first plot() should be moved outside the first for loop.

I came from MATLAB, and personally much prefer Makie.jl over Plots.jl.

Using GLMakie.jl, you get a nice window you can rotate around a bit like in MATLAB. And the layouting features are very good.

Code:

using GLMakie

I1=2;I2=1;I3=2/3;

fig = Figure() #create a figure
ax = Axis3(fig[1,1]) #put 3d axis into fig. 

for H in vcat(.01:0.05:0.46, .5, .54:0.05:1.5)
  y1=-1:.0001:0
  y2=sqrt.(Complex.(((2 .*H-1/I3).-(1/I1-1/I3) *y1 .^2)/(1/I2-1/I3)));
  y3=sqrt.(Complex.(((2 .*H-1/I2).-(1/I1-1/I2) *y1 .^2)/(1/I3-1/I2)));
  
  m=1;
  
  y1_new = Float64[]; 
  y2_new = Float64[];
  y3_new = Float64[];
  for k = 1:length(y1)
    if( imag(y2[k])==0 && imag(y3[k])==0 )
      push!(y1_new, y1[k]);
      push!(y2_new, y2[k]);
      push!(y3_new, y3[k]);
      m=m+1;
    end
  end
  if m>1
    lines!(ax,y1_new,y2_new,y3_new)
    lines!(ax,y1_new,-y2_new,y3_new)
    lines!(ax,y1_new,y2_new,-y3_new)
    lines!(ax,y1_new,-y2_new,-y3_new)
    
    lines!(ax,-y1_new,y2_new,y3_new)
    lines!(ax,-y1_new,-y2_new,y3_new)
    lines!(ax,-y1_new,y2_new,-y3_new)
    lines!(ax,-y1_new,-y2_new,-y3_new)
  end
end

fig

4 Likes