python 螺旋数组_4种matplotlib的阿基米德螺旋线画法和自然意义

论坛 期权论坛 期权     
选择匿名的用户   2021-5-28 00:24   10327   0

1 说明:

=====

1.1 阿基米德:(约公元前287~前212),古希腊伟大的数学家、力学家。

240e2f312e5cb9515a795bb641a40f35.png

1.2 阿基米德螺旋线:

最初是由阿基米德的老师柯农(欧几里德的弟子)发现的。柯农死后,阿基米德继续研究,又发现许多重要性质,因而这种螺线就以阿基米德的名字命名了。

1.3 python的matplotlib和turtle实现阿基米德螺旋线。

1.4 阿基米德螺旋线:等角螺旋线的自然意义,本文值得收藏。

2 静态图:

=======

2.1 代码一:

#参考代码:#https://www.zhezhier.com/view/609456846/#第1步:导入模块import matplotlib.pyplot as pltimport numpy as np#第2步:定义极坐标图plt.subplot(111, polar=True)#第3步:参数定义N = 4  #4个半圈=2个圆=4个180#x角度,100代表平滑度,越大越平滑xtheta = np.arange(0, N * np.pi, np.pi / 100)#画图plt.plot(xtheta, xtheta, '--r')#第4步:标题和图片展示plt.title('Archimedes spiral')plt.show()

2.2 图:

31226d1117b0337c860ea72aad35a4a9.png

2.3 4条阿基米德螺旋线代码:

import numpy as npimport matplotlib.pyplot as plt #推荐b=2b = 2.0n = 4  #几条螺旋线#2π代表一圈theta = np.linspace(0, 2 * np.pi, num=100)plt.subplot(111, projection='polar')y = b * thetafor i in range(n):    x = theta + 2 * np.pi * (i / n)    plt.plot(x, y)plt.show()

2.4 图:

5a15e6dd82f9296abb310214dcd76ec7.png

3 动态阿基米德螺旋线:

=================

3.1 代码:

#第1步:导入模块import numpy as npimport matplotlib.pyplot as pltfrom matplotlib import animation#第2步:定义图片和极坐标fig = plt.figure()plt.subplot(111, polar=True)#这个不能少plt.ylim([0, 30])#定义一个空的线条line, = plt.plot([], [], '--r')#第3步:初始化线条def init():    line.set_data([], [])    return line,#第4步:动画线条坐标设置def animate(i):    if i!=0:        theta = np.arange(0, i * np.pi, np.pi / 100)        line.set_data(theta, theta)    return line,#第5步:动画挂起anim = animation.FuncAnimation(fig, animate, init_func=init,                                 frames=8, interval=300, blit=True) plt.show()

3.2 图:

bb4d4ab4f8aa86cd81655a1fd177755d.gif

4 直角坐标画阿基米德螺旋线:等角螺旋线

================================

4.1 代码:

#https://www.jb51.net/article/177370.htm#第1步:导入模块import numpy as npimport matplotlib.pyplot as plt#第2步:定义等角螺旋线函数,默认值设定def plotSpiral(core=(0,0), fixed=10, phase=0, circle=4):  """绘制等角螺线  core- 等角螺线的中心坐标,tuple类型  fixed    - 等角螺线的固定角度,单位:度(°),推荐为10。fixed大于零则为顺时针螺线,小于零则为逆时针螺线  phase    - 初始相位,单位:圈(360°),默认为0。对顺时针螺线,该数值越大,螺线越大,对逆时针螺线则相反  circle   - 螺线可见部分的圈数,单位:圈(360°),默认为4  """  #设置  plt.axis("equal")  #原点坐标设置  plt.plot([core[0]], [core[1]], c='red', marker='+', markersize=10)  #参数和公式  fixed_rad = np.radians(90 + fixed)  theta = np.linspace(0, circle*2*np.pi, 361) + phase*2*np.pi  r = fixed_rad*np.exp(theta/np.tan(fixed_rad))  x = r*np.cos(theta) + core[0]  y = r*np.sin(theta) - core[1]  #划等角螺旋线  plt.plot(x, y, c='g')  #展示  plt.show()#第3步:调用函数,采用默认值plotSpiral()

4.2 图:

3c138385b7ea9093c6395cd3f3a71e50.png

5 3d上升的螺旋线:

==============

5.1 代码:

#参考代码:https://www.liangzl.com/get-article-detail-1342.html,对代码进行修改#第1步:导入模块import numpy as npimport matplotlib.pyplot as pltfrom matplotlib import animation#第2步:初始化画布fig = plt.figure(1)ax = fig.add_subplot(1, 1, 1, projection='3d')  # 指定三维空间做图#第3步:参数定义t = np.linspace(0, 4, 200)  # 在0到4之间,均匀产生200点的数组theta = t * 2 * np.pi  # 角度#中心坐标点core=(0,0,0)fixed_rad = np.radians(100)r = fixed_rad*np.exp(theta/np.tan(fixed_rad))# 生成曲线数组z = t+core[2]x = r*np.sin(theta)+core[0]y = r*np.cos(theta)+core[1]#第4步:运动点和线初始化定义# 运动的点point, = ax.plot([], [], [], 'ro', label='p')# 曲线line, = ax.plot([], [], [],'--g', label='line')#第5步:动画数据定义def animate(i):    line.set_xdata(x[:i + 1])    line.set_ydata(y[:i + 1])    line.set_3d_properties(z[:i + 1])    point.set_xdata(x[i])    point.set_ydata(y[i])    point.set_3d_properties(z[i])#第6步:动画挂起ani = animation.FuncAnimation(fig=fig,                              func=animate,                              frames=len(x),                              interval=200,                              repeat=False,                              blit=False)#第7步:设置显示的范围和描述,3d不能少ax.set_xlim(-1, 2)ax.set_ylim(-1, 2)ax.set_zlim(-1, 2)ax.set_xlabel('x')ax.set_ylabel('y')ax.set_zlabel('z')#第8步:标题名和图例设置# 标题ax.set_title('3D animate')#标题名在位置ax.view_init(30, 35)# 设置标签在最佳位置ax.legend(loc='best')#图片展示plt.show()

5.2 图:

8689106f089156abc53ca6500a7a0b25.gif

6 自然意义:

ca0959e90c7b6e0f6d7425024424f3e0.png

台风

93323801464cd28bdbaa5312cd167118.png

宇宙

613530372a7102594b449dfe56a33daa.png

玫瑰花

8bfd50b25dddc51ced0f7f5bfd92b84e.png

鹦鹉螺

0329c7a156ebbfbd1814250bab66a00d.png

螺丝钉

小结:

本文超级经典,值得收藏。

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP