Rado wrote: > Hello, > > To test the 3D plotting abilities of sage, I tried to implement some > basic tube plotting like the ones here > http://facstaff.unca.edu/mcmcclur/java/LiveMathematica/tubes.html > (mathematica handles those beautifully). > > The code is nice and short and I think the pretty picture that comes > out is good for SAGE posters or the show-off page in the wiki. To > compete with mathematica all that's left is putting nicer color > textures, but I don't know how to do that with JMOL. >
(CCing sage-support, since this seems like it would be of wider interest) This is nice! It's prettier than the shorter version: curve = vector([sin(3*x), sin(x)+2*sin(2*x), cos(x)-2*cos(2*x)]) parametric_plot(list(curve), (x, 0, 2*pi), thickness=30,aspect_ratio=[1,1,1]) Does anyone know why using the thickness keyword looks a little weird (like balls strung together, rather than a tube)? You can change the color by using the 'color' keyword. There are some predefined colors, or you can specify an RGB numeric list. curve = vector([sin(3*x), sin(x)+2*sin(2*x), cos(x)-2*cos(2*x)]) parametric_plot(list(curve), (x, 0, 2*pi), thickness=30,aspect_ratio=[1,1,1], color='red') Incidentally, I think the function should be changed to accept vectors, so you don't have to put the "list" command in there to get it to plot. > #Original idea: > http://facstaff.unca.edu/mcmcclur/java/LiveMathematica/tubes.html > #SAGE translation: Radoslav Kirov > > def vector_normalize(v): > return v/sqrt(v*v) > > x,s = var('x,s') > curve = vector([sin(x), cos(x),0]) > #if you are happy with the torus, try the trefoil knot > #curve = vector([sin(3*x), sin(x)+2*sin(2*x), cos(x)-2*cos(2*x)]) > tangent = diff(curve,x) > unit_tangent = vector_normalize(tangent) > normal = diff(unit_tangent,x) > #alternative is to cross_product with a random vector. This might be > faster but will make picture uglier. > #you will probably, need to check that the tangent is not parallel to > [1,1,1]. > #test_vector = vector([1,1,1]) > #normal = (test_vector.cross_product(unit_tangent)) > unit_normal = vector_normalize(normal) > unit_binormal = unit_normal.cross_product(unit_tangent) > radius = 0.3 > parametric_plot3d(list(curve + radius * cos(s) * unit_normal + radius > * sin(s) * unit_binormal), (x,0,2*pi),(s,0,2*pi),aspect_ratio=[1,1,1]) > > Also, a warning for people who come from the world of Mathematica: > > sage: v=Vector([2,1]) > sage: v.normalize() > (1, 1/2) > > I lost a good 15 min. on that. I am guessing this definition of > normalize comes from polynomials but its quite weird for regular > vector calculus. > > Ouch. That seems really out of place for vectors. I agree it ought to be changed. Thanks, Jason --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sage-edu" group. To post to this group, send email to sage-edu@googlegroups.com To unsubscribe from this group, send email to sage-edu+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-edu?hl=en -~----------~----~----~----~------~----~------~--~---