男单 618

生活象筒装的卫生纸,开始的时候怎么扯都不觉得在转,后来转的越来越快。

Sage绘制摆线动画

without comments

在Sage中绘制动画,实际上是先画出每一帧,再使用imagemagick将多幅图像转化为gif动画。先来看一个简单例子:

t,u=var(‘t,u’)
cc=[point((cos(t),sin(t)),pointsize=30,rgbcolor='red')+parametric_plot((cos(u),sin(u)),(0,t)) for t in srange(0.01,2*pi,0.2)]
myan=animate(cc,xmin=-1.5, xmax=1.5,ymin=-1.5, ymax=1.5,aspect_ratio=1)
show(myan)

第2行中每帧图像由两部分组成,一是动点,二是圆弧。这里,srange函数中的初值不能取零,否则会出错。第3行中将绘图的坐标范围固定,如果不固定,Sage会将当前图像主体放置在图像中央,自动调整坐标轴的显示范围。这一特性在绘制静态图像时,非常有用,但这样得到的动画往往不是我们想要的。

下面来看圆摆线x=a*(u-sin(u)), y=a*(1-cos(u)),  0<u<2*pi的绘制:

u=var(‘u’)
a=2
pic=[parametric_plot((a*(u-sin(u)),a*(1-cos(u))),(u,0,t),rgbcolor='red')\
+circle((a*t,a),a,rgbcolor='blue')\
+point((a*(t-sin(t)),a*(1-cos(t))),pointsize=20,rgbcolor='red')\
+line([(a*t,a),(a*(t-sin(t)),a*(1-cos(t)))],rgbcolor=’blue’) for t in srange(0.01,2*pi+0.1,0.2)]
bbb=animate(pic,xmin=-0.5,xmax=(2*pi+1)*a,ymin=-1, ymax=2*a+1,aspect_ratio=1)
show(bbb)

注:其他一些数学软件绘图时,如果不手工清除绘图区域,则上一个图像会保留下来,这与Sage的工作方式不同。Sage中的每一帧都是“全新”绘制的。

下面将其转化为交互式的图形:

@interact
def _(t=(0.01,2*pi,0.5)):
u=var(‘u’)
a=2
pic=parametric_plot((a*(u-sin(u)),a*(1-cos(u))),(u,0,t),rgbcolor=’red’)\
+circle((a*t,a),a,rgbcolor=’blue’)\
+point((a*(t-sin(t)),a*(1-cos(t))),pointsize=20,rgbcolor=’red’)\
+line([(a*t,a),(a*(t-sin(t)),a*(1-cos(t)))],rgbcolor=’blue’)
show(pic,xmin=-0.5,xmax=(2*pi+1)*a,ymin=-1, ymax=2*a+1,aspect_ratio=1)

由于刷新的问题,更新不连贯,拖放之后,需要等一下。

Written by amao

2010/01/21 at 22:23

Posted in sage

Tagged with

Leave a Reply