如何在圆的周长上画圆?

我正在尝试绘制这样的图:

https://img1.sycdn.imooc.com/65269fbd000140a103250262.jpg

我不知道如何在 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()

输出:

https://img1.sycdn.imooc.com/65269fc60001ef7501630140.jpg

慕虎7371278
浏览 107回答 1
1回答

皈依舞

0, 2pi可以使用正弦、余弦和在范围内均匀划分的角度:import numpy as npimport matplotlib.pyplot as pltnum_circ = 7rad_large = 7rad_small = 6thetas = 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 axisax.set_aspect('equal') # show circles as circlesplt.show()
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python