1 说明:
=====
1.1 阿基米德:(约公元前287~前212),古希腊伟大的数学家、力学家。
1.2 阿基米德螺旋线:
最初是由阿基米德的老师柯农(欧几里德的弟子)发现的。柯农死后,阿基米德继续研究,又发现许多重要性质,因而这种螺线就以阿基米德的名字命名了。
1.3 python的matplotlib和turtle实现阿基米德螺旋线。
1.4 阿基米德螺旋线:等角螺旋线的自然意义,本文值得收藏。
2 静态图:
=======
2.1 代码一:
#参考代码:#https://www.zhezhier.com/view/609456846/
#第1步:导入模块
import matplotlib.pyplot as plt
import 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 图:
2.3 4条阿基米德螺旋线代码:
import numpy as np
import matplotlib.pyplot as plt
#推荐b=2
b = 2.0
n = 4 #几条螺旋线
#2π代表一圈
theta = np.linspace(0, 2 * np.pi, num=100)
plt.subplot(111, projection=’polar’)
y = b * theta
for i in range(n):
x = theta + 2 * np.pi * (i / n)
plt.plot(x, y)
plt.show()
2.4 图:
3 动态阿基米德螺旋线:
=================
3.1 代码:
#第1步:导入模块
import numpy as np
import matplotlib.pyplot as plt
from 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 图:
4 直角坐标画阿基米德螺旋线:等角螺旋线
================================
4.1 代码:
#https://www.jb51.net/article/177370.htm
#第1步:导入模块
import numpy as np
import 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 图:
5 3d上升的螺旋线:
==============
5.1 代码:
#参考代码:https://www.liangzl.com/get-article-detail-1342.html,对代码进行修改
#第1步:导入模块
import numpy as np
import matplotlib.pyplot as plt
from 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 图:
6 自然意义:
台风
宇宙
玫瑰花
鹦鹉螺
螺丝钉