Example for the Ants on a Doughnut lab. We look at 3 paths, the last one being the most complicated.with(plots):X:=(cos(ss)+2)*cos(tt): Y:=(cos(ss)+2)*sin(tt): Z:=sin(ss):TorusPlot:=plot3d([X,Y,Z],ss=0..2*Pi,tt=0..2*Pi,style=wireframe):Path 1: Around the "Equator"alpha:=0*t; beta:=Pi*t;x:=(cos(alpha)+2)*cos(beta);y:=(cos(alpha)+2)*sin(beta);z:=sin(alpha);dx:=diff(x,t);dy:=diff(y,t);dz:=diff(z,t);Compute arc length:Integrand:=simplify(dx^2+dy^2+dz^2);F:=int(sqrt(Integrand),t=0..1);PathPlot:=spacecurve([x,y,z],t=0..1,numpoints=100,color=black,thickness=2):display3d(TorusPlot,PathPlot,scaling=constrained);Path 2: Around both "circles" simultaneouslyalpha:=2*Pi*t; beta:=Pi*t;x:=(cos(alpha)+2)*cos(beta);y:=(cos(alpha)+2)*sin(beta);z:=sin(alpha);dx:=diff(x,t);dy:=diff(y,t);dz:=diff(z,t);Compute arc length:Integrand:=simplify(dx^2+dy^2+dz^2);F:=evalf(Int(sqrt(Integrand),t=0..1));PathPlot:=spacecurve([x,y,z],t=0..1,numpoints=100,color=black,thickness=2):display3d(TorusPlot,PathPlot,scaling=constrained);Sample: Optimizing a class of paths. In the (beta, alpha) plane, we will go:(0,0) -> (k, Pi) -> (Pi/2, Pi) (then back again so that we'll find this path length and double it)The first part of the path is: alpha=Pi*t, beta=k*tThe second part we'll write after we get the arc length:alpha:=Pi*t; beta:=k*t;x:=(cos(alpha)+2)*cos(beta);y:=(cos(alpha)+2)*sin(beta);z:=sin(alpha);dx:=diff(x,t);dy:=diff(y,t);dz:=diff(z,t);Integrand:=simplify(dx^2+dy^2+dz^2);F:=Int(sqrt(Integrand),t=0..1)+(Pi/2 - k);plot(F,k=0..Pi/2);Soln:=fsolve(diff(F,k)=0,k,0.6..1.0);2*evalf(subs(k=Soln,F));Now we'll plot the path on the surface of our torus:with(plots):P1:=spacecurve([subs(k=Soln,x),subs(k=Soln,y),subs(k=Soln,z)],t=0..1,color=black,thickness=5):X:=(cos(ss)+2)*cos(tt); Y:=(cos(ss)+2)*sin(tt); Z:=sin(ss);Path2:=subs(ss=Pi, tt=(1-t)*(Pi/2-Soln)+t*(Pi/2+Soln),[X,Y,Z]);P2:=spacecurve(Path2,t=0..1,color=black,thickness=5):Path3:=subs(ss=(1-t)*Pi,tt=(1-t)*(Pi/2+Soln)+t*Pi,[X,Y,Z]);P3:=spacecurve(Path3,t=0..1,color=black,thickness=5):T:=plot3d([X,Y,Z],ss=0..2*Pi,tt=0..2*Pi,scaling=constrained,style=wireframe,shading=ZHUE):display3d({T,P1,P2,P3});