使半径取决于θ,我们可以有一个函数f,这样:
- 当距离角度超过 2 步时
theta1:f(t) = 1
- 在 1 和 2 步之外
f(1) = f(2) = 1
- 在
theta1 处存在f(0) = k 的变形,对于某些k
- 在 0 和 2 处,变形的切线应为零
- 对于负的
t,我们可以在绝对值上使用f
如果f 是一个多项式,它可能是4 次的,所以f = a*t**4 + b*t**3 + c*t**2 + d*t + e。符号数学库 sympy 可以在给定的约束条件下为这些参数找到合适的值。
from sympy import Eq, solve
from sympy.abc import a, b, c, d, e, t, k
f = a * t ** 4 + b * t ** 3 + c * t ** 2 + d * t + e
eq1 = Eq(f.subs(t, 0), k)
eq2 = Eq(f.subs(t, 1), 1)
eq3 = Eq(f.subs(t, 2), 1)
eq4 = Eq(f.diff(t).subs(t, 0), 0)
eq5 = Eq(f.diff(t).subs(t, 2), 0)
sol = solve([eq1, eq2, eq3, eq4, eq5], (a, b, c, d, e))
这会生成(经过一些重写后)f 的以下表达式:
k + (2 * t ** 2 - 9 * t + 11) * t ** 2 * (1 - k) / 4
现在,用这个函数画出变形的圆:
import matplotlib.pyplot as plt
import numpy as np
theta = np.linspace(0, 2 * np.pi)
k = 0.8
theta1 = 80 * np.pi / 180 # a deformation at theta 80 degrees
alpha = 36 * np.pi / 180 # have a special point every 36 degrees (10 on the circle)
th = theta - theta1 # the difference between the angles, still needs to be careful to make this difference symmetrical to zero
t = np.abs(np.where(th < np.pi, th, th - 2 * np.pi)) / alpha # use absolute value and let alpha represent a step of 1
r = np.where(t > 2, 1, k + (2 * t ** 2 - 9 * t + 11) * t ** 2 * (1 - k) / 4) # the deformed radius
plt.plot(np.cos(theta), np.sin(theta), ':r')
plt.plot(r * np.cos(theta), r * np.sin(theta), '-b')
plt.fill(r * np.cos(theta), r * np.sin(theta), color='blue', alpha=0.2)
for i in range(-5, 5):
plt.plot(np.cos(theta1 + i * alpha), np.sin(theta1 + i * alpha), 'xk')
plt.axis('equal')
plt.show()