python 画圆

mac2022-06-30  72

import numpy as np import matplotlib.pyplot as plt # ========================================== # 圆的基本信息 # 1.圆半径 r = 2.0 # 2.圆心坐标 a, b = (0., 0.) # ========================================== # 方法一:参数方程 theta = np.arange(0, 2*np.pi, 0.01) x = a + r * np.cos(theta) y = b + r * np.sin(theta) fig = plt.figure() axes = fig.add_subplot(111) axes.plot(x, y) axes.axis('equal') # ========================================== # 方法二:标准方程 x = np.arange(a-r, a+r, 0.01) y = b + np.sqrt(r**2 - (x - a)**2) fig = plt.figure() axes = fig.add_subplot(111) axes.plot(x, y) # 上半部 axes.plot(x, -y) # 下半部 plt.axis('equal') # ========================================== plt.show()

转载于:https://www.cnblogs.com/hhh5460/p/6361123.html

相关资源:简单实现python画圆功能
最新回复(0)