Python:画出笛卡尔心形曲线
极坐标方程:
极坐标画图:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
theta = np.linspace(0.0, 2 * np.pi, 1000)
a = 5
rho = a * (1 - np.sin(theta))
plt.subplot(polar=True)
plt.plot(theta, rho, c = 'r')
plt.show()
直角坐标画图:
python程序:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
theta = np.linspace(0.5*np.pi, 1.5*np.pi, 1000)
sintheta = np.sin(theta)
a = 1
y = a * sintheta * (1 - sintheta)
x = np.sqrt((1 - sintheta) ** 2 - y ** 2)
x1 = np.hstack((x,-x[::-1])) #x[::-1]意思是反转x
y1 = np.hstack((y,y[::-1]))
plt.plot(x1, y1, c = 'r')
plt.show()