如何在 Python Turtle 中绘制三角形的外接圆?
How can I draw a circumcircle of a triangle in Python Turtle?
拜托,你能帮我解决这个问题吗?我可以画一个三角形,也可以计算圆心(我不知道它是否有帮助),我已经计算了半径。但我不知道如何画一个圆圈本身。我的方式并没有连接所有的顶点。谢谢你的任何想法。
import turtle
import math
from math import pi
alfa=60 # in degrees
beta=40
gama=80
c = 100
sin_alfa = math.sin(pi/180*alfa) # in radians
sin_beta = math.sin(pi/180*beta)
sin_gama = math.sin(pi/180*gama)
a = c/sin_gama *sin_alfa # a,b calculated
b = c/sin_gama *sin_beta
board = turtle.Turtle()
board.forward(100) # base c
board.left(180-beta)
board.forward(a)
board.left(180-gama)
board.forward(b)
board.left(180-alfa)
rad = rad = a/2*sin_alfa # radius of a circumcircle
board.circle(rad)
你是想在三角形中间画圆圈吗?
如果是这样,那么您所要做的就是
# code for everything and triangle
board.up()
board.forward(50)
board.down()
# Rest of code
请详细说明
此修改后的代码将绘制一个接触所有角的圆。
import turtle
import math
from math import pi
alfa=60 # in degrees
beta=40
gama=80
c = 100
sin_alfa = math.sin(pi/180*alfa) # in radians
sin_beta = math.sin(pi/180*beta)
sin_gama = math.sin(pi/180*gama)
a = c/sin_gama *sin_alfa # a,b calculated
b = c/sin_gama *sin_beta
board = turtle.Turtle()
board.forward(100) # base c
board.left(180-beta)
board.forward(a)
board.left(180-gama)
board.forward(b)
board.left(180-alfa)
rad = a/(2*sin_alfa) # radius of a circumcircle
# shift pen to bottom-most point of the circle
board.up()
board.forward(c/2)
board.right(90)
board.forward(rad*(1-(1-sin_gama**2)**0.5))
board.down()
board.left(90)
# the circle
board.circle(rad)
turtle.done()
以下是光标移动方式的图形说明:
拜托,你能帮我解决这个问题吗?我可以画一个三角形,也可以计算圆心(我不知道它是否有帮助),我已经计算了半径。但我不知道如何画一个圆圈本身。我的方式并没有连接所有的顶点。谢谢你的任何想法。
import turtle
import math
from math import pi
alfa=60 # in degrees
beta=40
gama=80
c = 100
sin_alfa = math.sin(pi/180*alfa) # in radians
sin_beta = math.sin(pi/180*beta)
sin_gama = math.sin(pi/180*gama)
a = c/sin_gama *sin_alfa # a,b calculated
b = c/sin_gama *sin_beta
board = turtle.Turtle()
board.forward(100) # base c
board.left(180-beta)
board.forward(a)
board.left(180-gama)
board.forward(b)
board.left(180-alfa)
rad = rad = a/2*sin_alfa # radius of a circumcircle
board.circle(rad)
你是想在三角形中间画圆圈吗? 如果是这样,那么您所要做的就是
# code for everything and triangle
board.up()
board.forward(50)
board.down()
# Rest of code
请详细说明
此修改后的代码将绘制一个接触所有角的圆。
import turtle
import math
from math import pi
alfa=60 # in degrees
beta=40
gama=80
c = 100
sin_alfa = math.sin(pi/180*alfa) # in radians
sin_beta = math.sin(pi/180*beta)
sin_gama = math.sin(pi/180*gama)
a = c/sin_gama *sin_alfa # a,b calculated
b = c/sin_gama *sin_beta
board = turtle.Turtle()
board.forward(100) # base c
board.left(180-beta)
board.forward(a)
board.left(180-gama)
board.forward(b)
board.left(180-alfa)
rad = a/(2*sin_alfa) # radius of a circumcircle
# shift pen to bottom-most point of the circle
board.up()
board.forward(c/2)
board.right(90)
board.forward(rad*(1-(1-sin_gama**2)**0.5))
board.down()
board.left(90)
# the circle
board.circle(rad)
turtle.done()
以下是光标移动方式的图形说明: