心形函数绘制
心形曲线在数学上可通过参数方程表示,最常用的形式为:
x=16sin3(t)x = 16\sin^3(t)x=16sin3(t)
y=13cos(t)−5cos(2t)−2cos(3t)−cos(4t)y = 13\cos(t) - 5\cos(2t) - 2\cos(3t) - \cos(4t)y=13cos(t)−5cos(2t)−2cos(3t)−cos(4t)
其中参数 ttt 的取值范围为 [0,2π][0, 2\pi][0,2π]。该方程在笛卡尔坐标系中生成标准心形图案。
Python实现代码
import numpy as np
import matplotlib.pyplot as plt
t = np.linspace(0, 2*np.pi, 1000) # 参数t从0到2π
x = 16 * np.sin(t)**3 # x坐标计算
y = 13*np.cos(t) - 5*np.cos(2*t) - 2*np.cos(3*t) - np.cos(4*t) # y坐标计算
plt.figure(figsize=(8, 6))
plt.plot(x, y, color='red', linewidth=3) # 绘制红色心形线
plt.title('心形函数曲线', fontsize=14)
plt.axis('equal') # 等比例坐标轴
plt.grid(alpha=0.3)
plt.show()
运行效果:
- 生成平滑的对称心形曲线
- 顶部呈现双峰凹陷特征
- 底部形成尖点收敛
- 整体呈现经典的心形几何特征
此方程源于笛卡尔心形线的变体,通过调整系数可改变心形的宽高比和曲率。将参数 ttt 替换为 θ\thetaθ 也可转换为极坐标形式 r=a(1−sinθ)r = a(1 - \sin\theta)r=a(1−sinθ),但上述参数方程能生成更标准的心形图案。
931

被折叠的 条评论
为什么被折叠?



