为了账号安全,请及时绑定邮箱和手机立即绑定

如何在圆的周长上画圆?

如何在圆的周长上画圆?

慕虎7371278 2023-10-11 21:13:46
我正在尝试绘制这样的图:我不知道如何在 for 循环中找到较小圆圈的中心。首先,我尝试用较少数量的圆圈(例如2个)来绘制它,但我不知道为什么较小的圆圈是半圆?我的尝试:import numpy as npimport matplotlib.pyplot as pltr = 2, h = 1, k = 1axlim = 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**2plt.contour(X,Y,F,0)F1 = (X-(h+r))**2 + (Y-k)**2 - (r/3)**2plt.contour(X,Y,F1,0)F2 = (X-h)**2 + (Y-(k+r))**2 - (r/3)**2plt.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()输出:
查看完整描述

1 回答

?
皈依舞

TA贡献1851条经验 获得超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()

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

查看完整回答
反对 回复 2023-10-11
  • 1 回答
  • 0 关注
  • 64 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信