0

Please, could you help me with this? I can draw a triangle and also calculate the center of the circle (I don't know if it is even helpful) and I have calculated the radius. But I don't know how to draw a circle itself. The way I have it doesn't connect all the vertexes. Thank you for any ideas.

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)

2 Answers2

0

Are you trying to draw the circle in the middle of the triangle? if so then all you have to do is

# code for everything and triangle
board.up()
board.forward(50)
board.down()
# Rest of code

Please elaborate

IsraelW
  • 63
  • 9
0

This modified code would draw a circle that touches all corners.

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()

Here is a graphical explanation of how the cursor was shifted:

Rishabh Kumar
  • 2,342
  • 3
  • 13
  • 23
  • Thank you very much for yur answer. I have tried it and the result is this. It is a little bit inaccurate.It's just that turtle is not 100% precise? Is it OK? Thanks again.This is a picture that I get, C vertex seems to be a little off. [1]: https://i.stack.imgur.com/57D2y.png – Monika Sistkova Apr 09 '21 at 11:06
  • @MonikaSistkova You are right, I did a small calculation oopsie. I will post the correction. And yes turtle graphics is not that precise but its usually tolerable. The output that you get is definitely not that tolerable. Thanks for pointing out. – Rishabh Kumar Apr 09 '21 at 17:25
  • Please recheck the code and marked this answer as accepted if it helped you :) – Rishabh Kumar Apr 09 '21 at 17:31