用Python画出带内外接圆的正六边形
时间: 2024-02-16 22:35:39 浏览: 156
可以使用turtle库来画出带内外接圆的正六边形,代码如下:
```python
import turtle
import math
# 设置边长和圆半径
length = 100
r_out = length / math.sin(math.pi / 6)
r_in = length / math.tan(math.pi / 6)
# 定义画正六边形、外接圆、内切圆的函数
def draw_hexagon():
turtle.penup()
turtle.goto(length / 2, r_out)
turtle.pendown()
for i in range(6):
turtle.forward(length)
turtle.right(60)
def draw_outer_circle():
turtle.penup()
turtle.goto(0, r_out)
turtle.pendown()
turtle.circle(r_out)
def draw_inner_circle():
turtle.penup()
turtle.goto(0, r_in)
turtle.pendown()
turtle.circle(r_in)
# 调用函数画图
draw_hexagon()
draw_outer_circle()
draw_inner_circle()
# 隐藏画笔
turtle.hideturtle()
turtle.done()
```
运行这段代码,就可以在窗口中看到带内外接圆的正六边形啦~
阅读全文