On May 7, 2009, at 12:29 AM, 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.
>
> #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])

Cool.

> 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.

Either that or gaussian elimination, but I find that definition  
strange as well...

- Robert



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sage-edu" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-edu?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to