Plot the Theodorus Spiral with Plots

Tried to reproduce the following code from the link in Julia

But I can’t configure the graphics part correctly.
I show you where I have been:

#https://theredforgepublishinghouse.com/learn-maths-with-the-theodorus-spiral/
#clear all
using Plots
using  Printf
total_angle=0;
winding=0;
plt=plot();
@printf("x        hyp         X          Y           winding \n")
for x in 1:16
    hyp=sqrt(x+1);
    angle=atan(1/sqrt(x));
    total_angle=total_angle+angle;
    X=hyp*cos(total_angle);
    Y=hyp*sin(total_angle);
    degtotal_angle=total_angle*180/pi;
    winding=degtotal_angle/360;
    hypb=sqrt(x);
    Xb=hypb*cos(total_angle-angle);
    Yb=hypb*sin(total_angle-angle);
    plot!(plt,Vector[[0, 1],[0 ,0]],color=:blue,lw=3,leg=false) #first spoke
    plot!(plt,Vector[[0, X],[0, Y]],color=:blue,lw=3,leg=false)   #spokes
    plot!(plt,Vector[[Xb,X],[Yb, Y]],color=:blue,lw=3,leg=false)   #boundary
    @printf("%3d  %4.4f   %4.4f   %4.4f   %4.4f \n", x, hyp,  X,  Y,  winding); 
end
    plt

Hi, its just how Plots interprets the data vector.
Change
plot!(plt,Vector[[0, 1],[0 ,0]],color=:blue,lw=3,leg=false)
into
plot!(plt,[0, 1],[0 ,0],color=:blue,lw=3,leg=false)

Thanks, with that change and adding annotations = ((X + Xb) / 3, (Y + Yb) / 3, text (“$ x”,: left)). the graph is obtained:

plot!(plt,[0, 1],[0 ,0],color=:blue,lw=3,leg=false) #first spoke
plot!(plt,[0, X],[0, Y],color=:blue,lw=3,leg=false)   #spokes
plot!(plt,[Xb,X],[Yb, Y],color=:blue,lw=3,leg=false,annotations=((X+Xb)/3, (Y+Yb)/3, text("$x", :left)))   #boundary

Theodorus Spiral

1 Like