Ask Your Question
3

Animate rotating polytope

asked 2017-06-27 10:55:06 +0100

Akababa gravatar image

updated 2017-06-27 11:16:32 +0100

Hello, I'm trying to save an animation of a rotating polytope as a gif. So far the best I have is this:

n=49
t = (2*pi/n).n()
M=matrix([[cos(t),0,sin(t)],[0,1,0],[-sin(t),0,cos(t)]])
p=polytopes.cube()
vl = [v[:3] for v in p.vertices()]
sf = [p]
for i in range(n):
    vl = [M*v for v in vl]
    sf.append(Polyhedron(vl))
s=animate(sf)
s.gif(savefile="an.gif")

which outputs this:

https://media.giphy.com/media/3o7bufpi3S8f1dnlNm/giphy.gif (image description)

media.giphy.com/media/3o7bufpi3S8f1dnlNm/giphy.gif (Sorry, I need more karma to post links)

My questions: 1. how can I get the axes to stay constant so it looks more like a rotating object? 2. Is there a faster/cleaner way to do this?

edit retag flag offensive close merge delete

Comments

1

5 years ago, I managed to do animation of 3d sage graphics objects out of tachyon figures. See this blog post.

Sébastien gravatar imageSébastien ( 2017-06-27 13:50:37 +0100 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2017-06-28 17:58:32 +0100

ndomes gravatar image

To get the rotation axis stay constant, add an enveloping circle making this invisible with opacity = 0. Further set aspect_ratio=(1,1,1) as an option of animate.

r = 2
y_axis = [r*vector((0,-1,0)),r*vector((0,1,0))]

var('alpha')
C = parametric_plot((r*cos(alpha),0,r*sin(alpha)),(alpha,0,2*pi),opacity=0)

n=19
t = (2*pi/n).n()
M=matrix([[cos(t),0,sin(t)],[0,1,0],[-sin(t),0,cos(t)]])
p=polytopes.cube()
vl = [v[:3] for v in p.vertices()]
sf = [] #[p]
for i in range(n):
    vl = [M*v for v in vl]
    sf.append(Polyhedron(vl).plot(color='green',opacity=0.5,frame=False)+ 
              C + line(y_axis,color='gold',thickness=2))
s=animate(sf,aspect_ratio=(1,1,1))
s.gif(savefile="an.gif")
edit flag offensive delete link more

Comments

Thanks? Btw where can I find a list of all plot arguments?

Akababa gravatar imageAkababa ( 2017-06-29 04:48:40 +0100 )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: 2017-06-27 10:55:06 +0100

Seen: 512 times

Last updated: Jun 28 '17