Ask Your Question
0

Animated sphere

asked 2012-05-22 12:45:30 +0200

Albertsss gravatar image

I plotted an union of parametric curves in 3D (like a rollercoaster) and I want to create a solid sphere (radius of 0.5 approx.) that moves along the whole curve. You can do this in sage?

edit retag flag offensive close merge delete

Comments

Does http://ask.sagemath.org/question/1422/3d-animation-with-tachyon help? It's unclear whether the issue is making the spheres, or the technical aspect of making a 3d animation (which is not as seamless as it should be yet).

kcrisman gravatar imagekcrisman ( 2012-05-22 13:39:10 +0200 )edit

The issue is make de animation, I know how to plot a sphere in one point of the space, but I don't know how move the sphere along de curve. Thanks for answer!

Albertsss gravatar imageAlbertsss ( 2012-05-22 13:46:27 +0200 )edit

Did the other one help? Otherwise put your exact code and ask again, and someone will probably be able to help.

kcrisman gravatar imagekcrisman ( 2012-05-22 16:59:02 +0200 )edit

No jajajaj I try to explain my project better. Approximately, I have this: c1=parametric_plot3d((t,0,0),(0,1)) c2=parametric_plot3d((t,t^2,t^3),(0,1)) s=sphere(center=(0,0,0),size=0.5,color='black') c1+c2+s This plot two curves and the sphere in (0,0,0), I want to move the sphere along these two curves. Also, kcrisman, thank you very much for the answers!!

Albertsss gravatar imageAlbertsss ( 2012-05-22 17:11:49 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
4

answered 2012-05-22 18:08:10 +0200

niles gravatar image

updated 2012-05-24 18:00:26 +0200

kcrisman gravatar image

For any animation, you should write a function to produce the successive frames. Something like the following, for example:

sage: var('t')
t
sage: c1=parametric_plot3d((t,0,0),(0,1),thickness=2)
sage: c2=parametric_plot3d((t,t^2,t^3),(0,1),thickness=2)
def frame(i):
    return c1+c2+sphere(center=(i,i^2,i^3),size=.03,color='black')+sphere(center=(0,0,0),size=.03,color='black')

Then you can make a list of frames as

frames = [frame(i) for i in sxrange(0,1,.1)]

To animate them, use a modified version of @kcrisman 's answer to a similar question:

DATA = tmp_dir() # in the notebook, this will already be set to some temporary directory
for i in range(len(frames)):
    saved[i].save(filename=DATA+'mypic%08d.png'%i)

os.system('cd '+DATA+'; convert -delay %s -loop %s *.png "Done.gif"'%(int(100),int(2)))
os.system('ls '+DATA)

Note that with the patch at Trac 12827 applied, you can use the animate command directly:

A = animate(frames)
A.show()

For a longer animation or different format, saving the frames as separate images is probably better. The convert utility from ImageMagick works great for gifs, and ffmpeg is good for other video formats.

edit flag offensive delete link more

Comments

Does this really work? I have a feeling you have something else installed (like one of your custom patches at the other questions about this), because I get just errors. For instance, nowhere do you call Tachyon in the code above.

kcrisman gravatar imagekcrisman ( 2012-05-23 23:28:07 +0200 )edit

ack! You're right -- I forgot I have just one patch applied . . . I'll correct the post now!

niles gravatar imageniles ( 2012-05-24 08:56:53 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2012-05-22 12:45:30 +0200

Seen: 1,145 times

Last updated: May 24 '12