indiego
indiego

Reputation: 1

How to draw any right angled triangle with turtle graphics

How to specify angles?

def isosceles(a, b):
    side =sqrt(a ** 2 + b ** 2)
    turtle.forward(b)
    ???
    turtle.forward(side)

Upvotes: 0

Views: 696

Answers (2)

NameVergessen
NameVergessen

Reputation: 644

If you ware to do try this I would eiter try the origins function to. Or if you need or want to work with the degree you could try the following:

from math import atan2, degrees
import turtle


def isosceles(a, b, man=True):
    origin = turtle.pos()
    turtle.forward(a)
    turtle.left(90)
    turtle.forward(b)
    if man: # origin solution
        turtle.goto(origin)
    else: # manual solution
        side = sqrt(a ** 2 + b ** 2)
        angle = degrees(atan2(a / b))
        turtle.left(180 - angle)
        turtle.forward(side)
        

Upvotes: 1

quamrana
quamrana

Reputation: 39354

There is no need to calculate the length of the hypotenuse (or an internal angle) if you can just return to an origin:

import turtle

def isosceles(a, b):
    origin = turtle.pos()
    turtle.forward(a)
    turtle.left(90)
    turtle.forward(b)
    turtle.goto(origin)

isosceles(30,40)

Upvotes: 1

Related Questions