Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

Produces an animation of a moving Frenet frame along with a lot of curvature and torsion.

Project: Math 211
Views: 190
#initializations from sage.plot.plot3d.shapes import Box t = var('t') #length function for 3-dimensional vectors def length(v): return sqrt(v[0]^2+v[1]^2+v[2]^2) #components of the path gamma x(t) = (cos(3*t)+2)*cos(2*t) y(t) = (cos(3*t)+2)*sin(2*t) z(t) = -sin(3*t) #the path gamma gamma = vector([x,y,z]) #start and end points a,b a = 0 b = 2*pi #path plot P = parametric_plot3d(gamma(t),(t,a,b),frame=False) #auxiliary transparent boundary box for better-looking animations #set box dimensions so that each frame lies inside it boundary = Box([3.1,3.1,2.1],opacity=0,frame=False) #Frenet frame T = gamma.diff(t)/length(gamma.diff(t)) N = T.diff(t)/length(T.diff(t)) B = T.cross_product(N) #graphical representations of the Frenet frame def Tarrow(t): return arrow(gamma(t),gamma(t)+T(t),color='green',frame=False) def Narrow(t): return arrow(gamma(t),gamma(t)+N(t),color='red',frame=False) def Barrow(t): return arrow(gamma(t),gamma(t)+B(t),color='purple',frame=False) #all of the elements we want to plot simultaneously at time t def frenet_plot(t): return P + boundary + Tarrow(t) + Narrow(t) + Barrow(t) #curvature and torsion #note the novel extrinsic expression for tau kappa = length(gamma.diff(t).cross_product(gamma.diff(t).diff(t)))/length(gamma.diff(t))^3 tau = (gamma.diff(t).cross_product(gamma.diff(t).diff(t))).dot_product(gamma.diff(t).diff(t).diff(t))/length(gamma.diff(t).cross_product(gamma.diff(t).diff(t)))^2 #simultaneous plot of curvature and torsion ktplot = Graphics() ktplot += plot(kappa,(t,a,b),color='green') ktplot += plot(tau,(t,a,b),color='red') #add labels to the curvature/torsion plot ktplot += text("curvature",(b,1.5),color='green') ktplot += text("torsion",(b,1),color='red') #set the number of frames in the movie #test your setup with low num_frames (say 5 or 10) and then boost num_frames to 60 or 100 (or more?) for your final animation num_frames = 100 #animate the frames of the movie frenet_movie = animate([frenet_plot(t) for t in srange(a,b,(b-a)/num_frames)]) #display the animation and the curvature/torsion plot frenet_movie.show() ktplot.show() #save the animation and plot frenet_movie.save('frenet_movie.gif') ktplot.save('ktplot.png')