如何在圆的周长上绘制圆?

时间:2020-10-05 12:14:44

标签: python numpy matplotlib

我正在尝试绘制类似这样的东西:

Circles

我不知道如何在for循环中找到较小圆圈的中心。首先,我尝试用较小的圆(例如2)绘制它,但我不知道为什么较小的圆是半圆?

我的尝试:

import numpy as np
import matplotlib.pyplot as plt

r = 2, h = 1, k = 1

axlim = r + np.max((abs(h),np.max(abs(k))))
x = np.linspace(-axlim, axlim, 100)


X,Y = np.meshgrid(x,x)

F = (X-h)**2 + (Y-k)**2 - r**2
plt.contour(X,Y,F,0)


F1 = (X-(h+r))**2 + (Y-k)**2 - (r/3)**2
plt.contour(X,Y,F1,0)

F2 = (X-h)**2 + (Y-(k+r))**2 - (r/3)**2
plt.contour(X,Y,F2,0)

plt.gca().set_aspect('equal')
plt.axis([-4*r, 4*r, -4*r,4*r])
# plt.axis('off')
plt.show()

输出: enter image description here

1 个答案:

答案 0 :(得分:3)

可以使用在0, 2pi范围内平均划分的正弦,余弦和角度:

import numpy as np
import matplotlib.pyplot as plt

num_circ = 7
rad_large = 7
rad_small = 6
thetas = np.linspace(0, 2 * np.pi, num_circ, endpoint=False)

fig, ax = plt.subplots()
ax.add_patch(plt.Circle((0, 0), rad_large, fc='none', ec='navy'))
for theta in thetas:
    ax.add_patch(plt.Circle((rad_large * np.cos(theta), rad_large * np.sin(theta),), rad_small, fc='none', ec='crimson'))
ax.autoscale_view() # calculate the limits for the x and y axis
ax.set_aspect('equal') # show circles as circles
plt.show()

example plot