0
def drawTri(a):
    b = (a*math.tan(45))
    c = (a/math.cos(45))

    t.forward(a)
    t.left(135)
    t.forward(c)
    t.left(135)
    t.forward(b)

enter image description here

cdlane
  • 40,441
  • 5
  • 32
  • 81

4 Answers4

0
import turtle

def drawTri(a):
    hyp = a * 2**0.5
    s = turtle.Screen()
    t = turtle.Turtle()
    t.forward(a)
    t.left(135)
    t.forward(hyp)
    t.left(135)
    t.forward(a)
inspectorG4dget
  • 110,290
  • 27
  • 149
  • 241
0

The problem here is close to that described in Basic trigonometry isn't working correctly in python

The turtle module uses degrees for angles, the math module uses radians

To calculate the cosine of 45 degrees you can use

math.cos(math.radians(45))
Community
  • 1
  • 1
James K
  • 3,692
  • 1
  • 28
  • 36
  • 1
    Alternatively, you can also switch the turtle to use radians via `turtle.radians()` and then calculate `math.cos(math.pi / 4)` – cdlane Oct 06 '16 at 22:28
0

Who needs angles?

def drawTri(a):
    x, y = turtle.position()
    turtle.setx(x + a)
    turtle.sety(y + a)
    turtle.goto(x, y)
cdlane
  • 40,441
  • 5
  • 32
  • 81
0

i made a relay simple way of making a right angle triangle i also added some other helpful things to know about python turtle that is you didn't already know them they should be helpful(i know you already have an answer but i just think that this is a much simpler way)

import turtle
t = turtle
f = t.forward
r = t.right
t.color('blue','yellow')
t.begin_fill()
f(70)
r(135)
f(100)
r(135)
f(70)
r(135)
t.end_fill()

t.penup()
t.setposition(-50,30)
t.pendown()
t.color('blue','yellow')
t.begin_fill()
f(70)
r(135)
f(100)
r(135)
f(70)
r(135)
t.end_fill()

there are two triangles there and its the extra stuff that makes it so bulky

Alex
  • 5
  • 5