ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 24 May 2012 08:56:53 +0200Animated spherehttps://ask.sagemath.org/question/8993/animated-sphere/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?Tue, 22 May 2012 12:45:30 +0200https://ask.sagemath.org/question/8993/animated-sphere/Comment by Albertsss for <p>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?</p>
https://ask.sagemath.org/question/8993/animated-sphere/?comment=19751#post-id-19751No 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!!
Tue, 22 May 2012 17:11:49 +0200https://ask.sagemath.org/question/8993/animated-sphere/?comment=19751#post-id-19751Comment by kcrisman for <p>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?</p>
https://ask.sagemath.org/question/8993/animated-sphere/?comment=19752#post-id-19752Did the other one help? Otherwise put your exact code and ask again, and someone will probably be able to help.Tue, 22 May 2012 16:59:02 +0200https://ask.sagemath.org/question/8993/animated-sphere/?comment=19752#post-id-19752Comment by Albertsss for <p>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?</p>
https://ask.sagemath.org/question/8993/animated-sphere/?comment=19754#post-id-19754The 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!Tue, 22 May 2012 13:46:27 +0200https://ask.sagemath.org/question/8993/animated-sphere/?comment=19754#post-id-19754Comment by kcrisman for <p>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?</p>
https://ask.sagemath.org/question/8993/animated-sphere/?comment=19755#post-id-19755Does 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).Tue, 22 May 2012 13:39:10 +0200https://ask.sagemath.org/question/8993/animated-sphere/?comment=19755#post-id-19755Answer by niles for <p>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?</p>
https://ask.sagemath.org/question/8993/animated-sphere/?answer=13600#post-id-13600For 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](http://ask.sagemath.org/question/1422/3d-animation-with-tachyon):
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](http://trac.sagemath.org/sage_trac/ticket/12827) applied, you can use the `animate` command directly:
A = animate(frames)
A.show()
<img src="/upfiles/13377207341243501.gif" width="230px"></img>
For a longer animation or different format, saving the frames as separate images is probably better. The `convert` utility from [`ImageMagick`](http://www.imagemagick.org/Usage/anim_basics/) works great for gifs, and [`ffmpeg`](http://ffmpeg.org/faq.html#How-do-I-encode-single-pictures-into-movies_003f) is good for other video formats.Tue, 22 May 2012 18:08:10 +0200https://ask.sagemath.org/question/8993/animated-sphere/?answer=13600#post-id-13600Comment by niles for <p>For any animation, you should write a function to produce the successive frames. Something like the following, for example:</p>
<pre><code>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')
</code></pre>
<p>Then you can make a list of frames as</p>
<pre><code>frames = [frame(i) for i in sxrange(0,1,.1)]
</code></pre>
<p>To animate them, use a modified version of <a href="/users/41/kcrisman/">@kcrisman</a> 's answer to <a href="http://ask.sagemath.org/question/1422/3d-animation-with-tachyon">a similar question</a>:</p>
<pre><code>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)
</code></pre>
<hr/>
<p>Note that with the patch at <a href="http://trac.sagemath.org/sage_trac/ticket/12827">Trac 12827</a> applied, you can use the <code>animate</code> command directly:</p>
<pre><code>A = animate(frames)
A.show()
</code></pre>
<p><img src="/upfiles/13377207341243501.gif" width="230px"/></p>
<p>For a longer animation or different format, saving the frames as separate images is probably better. The <code>convert</code> utility from <a href="http://www.imagemagick.org/Usage/anim_basics/"><code>ImageMagick</code></a> works great for gifs, and <a href="http://ffmpeg.org/faq.html#How-do-I-encode-single-pictures-into-movies_003f"><code>ffmpeg</code></a> is good for other video formats.</p>
https://ask.sagemath.org/question/8993/animated-sphere/?comment=19744#post-id-19744ack! You're right -- I forgot I have just one patch applied . . . I'll correct the post now!Thu, 24 May 2012 08:56:53 +0200https://ask.sagemath.org/question/8993/animated-sphere/?comment=19744#post-id-19744Comment by kcrisman for <p>For any animation, you should write a function to produce the successive frames. Something like the following, for example:</p>
<pre><code>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')
</code></pre>
<p>Then you can make a list of frames as</p>
<pre><code>frames = [frame(i) for i in sxrange(0,1,.1)]
</code></pre>
<p>To animate them, use a modified version of <a href="/users/41/kcrisman/">@kcrisman</a> 's answer to <a href="http://ask.sagemath.org/question/1422/3d-animation-with-tachyon">a similar question</a>:</p>
<pre><code>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)
</code></pre>
<hr/>
<p>Note that with the patch at <a href="http://trac.sagemath.org/sage_trac/ticket/12827">Trac 12827</a> applied, you can use the <code>animate</code> command directly:</p>
<pre><code>A = animate(frames)
A.show()
</code></pre>
<p><img src="/upfiles/13377207341243501.gif" width="230px"/></p>
<p>For a longer animation or different format, saving the frames as separate images is probably better. The <code>convert</code> utility from <a href="http://www.imagemagick.org/Usage/anim_basics/"><code>ImageMagick</code></a> works great for gifs, and <a href="http://ffmpeg.org/faq.html#How-do-I-encode-single-pictures-into-movies_003f"><code>ffmpeg</code></a> is good for other video formats.</p>
https://ask.sagemath.org/question/8993/animated-sphere/?comment=19748#post-id-19748Does 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.Wed, 23 May 2012 23:28:07 +0200https://ask.sagemath.org/question/8993/animated-sphere/?comment=19748#post-id-19748