animations of raytraces of 3d plots.

193 views
Skip to first unread message

Christopher Olah

unread,
Feb 17, 2010, 1:28:04 PM2/17/10
to sage-s...@googlegroups.com
Greetings!

I've been trying to make animations of Tachyon raytraced 3d plots, so
that people can see a plot from multiple angles without java. (It
could also be used to visualise a forth dimension...) None of my
attempts have worked....

The best strategy I've had was:

sage: b = parametric_plot3d((u^2, v, u*v), [u, -1, 1], [v, -1, 1],
viewer='tachyon')
sage: animate([b.rotateY( 2*pi*(j/6) ) for j in range(6)])

But that didn't work either... I seem to be over my head in the
internal magic of sage. Can someone help me?

Thanks,

Christopher

Robert Bradshaw

unread,
Feb 17, 2010, 1:52:13 PM2/17/10
to sage-s...@googlegroups.com


Animate doesn't understand 3d graphics objects. This shouldn't be too
hard to fix, is anyone working on that?

- Robert


Christopher Olah

unread,
Feb 17, 2010, 3:33:40 PM2/17/10
to sage-s...@googlegroups.com
I think you misunderstand. I'm not passing a 3d object to animate (or
at least, I'm not trying to...). I'm passing a list of images of a 3d
object.

The problem is that I'm having trouble geting that list. I'm trying to
use Tachyon to render images, but... It's not working very well.

> --
> To post to this group, send email to sage-s...@googlegroups.com
> To unsubscribe from this group, send email to
> sage-support...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/sage-support
> URL: http://www.sagemath.org
>

Jason Grout

unread,
Feb 17, 2010, 9:28:40 PM2/17/10
to sage-s...@googlegroups.com

My guess is that since http://trac.sagemath.org/sage_trac/ticket/2872
has been merged, the above code will work in sage 4.3.3. Does anyone
have an alpha they can try it in? You might have to fiddle with the
viewer='tachyon' bit, though.

Thanks,

Jason

Marshall Hampton

unread,
Feb 18, 2010, 8:14:18 AM2/18/10
to sage-support
I recommend using ffmpeg for stuff like that, it will do a better job
than animate as long as animate is just using imagemagick. You need
to save the image files with sequential names. I can post an example
if you are interested.

-Marshall Hampton

On Feb 17, 2:33 pm, Christopher Olah <christopherolah...@gmail.com>
wrote:


> I think you misunderstand. I'm not passing a 3d object to animate (or
> at least, I'm not trying to...). I'm passing a list of images of a 3d
> object.
>
> The problem is that I'm having trouble geting that list. I'm trying to
> use Tachyon to render images, but... It's not working very well.
>
> On Wed, Feb 17, 2010 at 1:52 PM, Robert Bradshaw
>

Jason Grout

unread,
Feb 27, 2010, 4:08:33 PM2/27/10
to sage-s...@googlegroups.com
On 02/18/2010 07:14 AM, Marshall Hampton wrote:
> I recommend using ffmpeg for stuff like that, it will do a better job
> than animate as long as animate is just using imagemagick. You need
> to save the image files with sequential names. I can post an example
> if you are interested.

Someone might be interested in reviewing #7298: use html5 video tag for
animations:

"The attached patch adds support for creating Ogg Theora videos from
animation objects.

The resulting video files are embedded into the notebook using the html5
video tag. "

Thanks,

Jason

Marshall Hampton

unread,
Feb 27, 2010, 11:33:42 PM2/27/10
to sage-support
#7298 depends on #7297, "spkg's for libogg and libtheora". I tried to
review that and got stuck/frustrated with compilation problems. I
encourage someone else to give it a try. I think it might be easier
on linux than OS X (I usually do development work on OS X, especially
for notebook related work).

-Marshall

Christopher Olah

unread,
Mar 3, 2010, 12:08:59 PM3/3/10
to sage-s...@googlegroups.com
On Thu, Feb 18, 2010 at 8:14 AM, Marshall Hampton <hamp...@gmail.com> wrote:
> I recommend using ffmpeg for stuff like that, it will do a better job
> than animate as long as animate is just using imagemagick.  You need
> to save the image files with sequential names.  I can post an example
> if you are interested.

Sure.

calc...@aol.com

unread,
Mar 3, 2010, 4:23:08 PM3/3/10
to sage-s...@googlegroups.com
BTW, tachyon is supposed to run over MPI. Can I use SAGE to run
tachyon over a cluster?

TIA,
A. Jorge Garcia
http://calcpage.tripod.com

Teacher & Professor
Applied Mathematics, Physics & Computer Science
Baldwin Senior High School & Nassau Community College

Marshall Hampton

unread,
Mar 3, 2010, 7:25:36 PM3/3/10
to sage-support
Okay, this is somewhat baroque but might be helpful. One of the main
things is the zero-padding of file names, e.g. in the line "fname =
prelabel + '0'*(3-len(str(i)))+str(i)":

def tachbs(p, th = .2, fade = 1.0, xres = 500, yres = 500, **kwds):
c_center = [2*max([q[i] for q in p.vertices()]) for i in range(3)]
c_center[0],c_center[1] = c_center[0]*cos(th)+c_center[1]*sin(th),-
c_center[0]*sin(th)+c_center[1]*cos(th)
t = Tachyon(xres = xres, yres = yres, camera_center = c_center,
**kwds)
lightc = [x for x in c_center]
lightc[2] += 5
t.light(lightc,.5,(1.0,0.0,1.0))
t.texture('mattered',color = (1.0,0,0), ambient = .2*fade, opacity
= 1.0*fade, diffuse = .8*fade)
t.texture('matteblue',color = (0,0,1.0), ambient = .2*fade,
opacity = 1.0*fade, diffuse = .8*fade)
for q in p.vertices():
t.sphere(q,.05,'mattered')

for q in p.vertex_adjacencies():
q1 = q[0]
for q2 in q[1]:
t.fcylinder(p.vertices()[q1], p.vertices()[q2], .01,
'matteblue')
return t

def makeblackframe(fname, xres = 500, yres = 500):
t = Tachyon(xres = xres, yres = yres)
t.save(fname)

pico = polytopes.icosahedron()
prelabel = 'demo'
npi = RDF(pi)

frames = 120
for i in srange(0,frames):
if mod(i,20)==0: print i
fname = prelabel + '0'*(3-len(str(i)))+str(i)
tachbs(pico,th = 2.0*npi*i/(frames-1.0), antialiasing=True,
raydepth = 6).save(DATA+fname+'.png')

makeblackframe(DATA+ prelabel + '0'*(3-len(str(i+1)))+str(i+1)
+'.png')

os.system('ffmpeg -qmax 2 -r 20 -i ' + DATA + prelabel + '%3d.png ./'
+ prelabel +'.mp4')


-Marshall

On Mar 3, 11:08 am, Christopher Olah <christopherolah...@gmail.com>
wrote:

Jason Grout

unread,
Mar 3, 2010, 8:30:32 PM3/3/10
to sage-s...@googlegroups.com
On 03/03/2010 06:25 PM, Marshall Hampton wrote:
> Okay, this is somewhat baroque but might be helpful. One of the main
> things is the zero-padding of file names, e.g. in the line "fname =
> prelabel + '0'*(3-len(str(i)))+str(i)":


You could use the python formatting magic:

sage: "%03d"%1
'001'
sage: "%03d"%11
'011'
sage: "%03d"%199
'199'
sage: "%03d"%1999
'1999'

See http://docs.python.org/library/stdtypes.html#string-formatting for
more options.


Thanks,

Jason

Marshall Hampton

unread,
Mar 3, 2010, 9:00:19 PM3/3/10
to sage-support
Ah, cool, I thought there might be a slicker way to do that but I was
too lazy to look it up :)
Thanks,
Marshall

Robert Bradshaw

unread,
Mar 4, 2010, 3:50:12 AM3/4/10
to sage-s...@googlegroups.com
On Mar 3, 2010, at 1:23 PM, Calc...@aol.com wrote:

> BTW, tachyon is supposed to run over MPI. Can I use SAGE to run
> tachyon over a cluster?

Sage just calls the tachyon executable, so if you (re)compile tachyon
with MPI support it might just work. Of course if you're doing an
animation it's trivial to parallelize the individual frames (though
you might run out of memory before you run out of CPU in that case).

- Robert

Marshall Hampton

unread,
Mar 4, 2010, 7:45:00 AM3/4/10
to sage-support
Looks like for simpler images tachyon uses around 5-10 MB of memory.
Cranking up the raydepth and size and complexity of objects could get
that up to 15-20 MB pretty easily. I've never done a really complex
scene, i.e. realistic stuff with thousands of objects. For my
polyhedral movies the bottleneck often is on the Sage end of things.

-Marshall

On Mar 4, 2:50 am, Robert Bradshaw <rober...@math.washington.edu>
wrote:

Reply all
Reply to author
Forward
0 new messages