男单 618

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

Archive for the ‘sage’ Category

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

一月 21st, 2010 at 10:23 下午

Posted in sage

Tagged with

使用Sage绘制动画的一个例子

without comments

先把代码放在这里,有时间再解释:

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)
show(myan)

Written by amao

一月 15th, 2010 at 1:29 上午

Posted in sage

Tagged with

Sage Tutorial中文版

with one comment

Sage Tutorial是一份快速了解Sage的入门文档,花了两周多的时间将其翻译为中文。但是“Some more advanced mathematics”一节没有翻译,因为完全不熟悉这一节所涉及到的内容。

第一次翻译开源软件的技术文档,水平有限,希望各位多提意见,任何方面的都可以。如果没有大的问题,大概一周后会向Sage开发组提交。

源文件使用Sphinx管理,PDF文件是由自动转换而来的LaTeX文件编译的,因此其中很多格式不符合中文的习惯。所以请大家先以HTML文件为准,最后发布前,我会手工调整LaTeX文件后再编译。

Email: amao@ai7.org

相关内容:翻译Sage文档的准备工作

Sage Tutorial 中文版rst源文件

Sage Tutorial 中文版(HTML)

Sage Tutorial 中文版(PDF)

Written by amao

一月 9th, 2010 at 10:43 上午

Posted in linux, python, sage

Tagged with ,