elvalad

修仙
Mathematica 迭代函数

学习Mathematica迭代函数的几个画图例子:

1.三角形沿着某一点旋转

verticse = {{0, 0}, {1, 0}, {1/2, Sqrt[3]/2}};
tri = Line[verticse /. {a_, b__}->{a, b, a}];
Graphics[tri]

rotation[gr_] := Rotate[gr, Pi/13, {1, 1}];
Graphics[NestList[rotation, tri, 30]]

2.绘出迭代平移之后的三角形

translation[gr_] := Translate[gr, verticse];
Graphics[{RGBColor[0.32, 0.77, 1.], NestList[translation, tri, 5]}]

3.Sierpinski Triangle

SierpinskiTriangle[iter_, opts : OptionsPattern[Graphics]] :=
Module[{vertics, vecs},
vertics = N[{{0, 0}, {1, 0}, {1/2, 1}}];
vecs = 0.5 vertics;
Graphics[
{Blue, Nest[{Blue, Translate[Scale[#, 0.5, {0., 0.}], vecs]} &,
Polygon[vertics], iter]}, opts]]
 
SierpinskiTriangle[8, ImageSize -> 512]

参考资料:

posted on 2014-10-26 20:27  elvalad  阅读(1897)  评论(0编辑  收藏  举报