Topic 19 - Turtle Triangles

Right Angled Isosceles Triangles

Back in lesson 11 we drew concentric squares by moving the turtle out by a small amount. An alternative way to move the turtle's starting point is to use Pythagoras' Theorem. We need to find a point to the right and below the bottom right corner of the current square. This can be seen as lying on the corner of a right angled triangle as follows:

The red circle is drawn around the starting point for the next square.

The triangle shown has one angle of 90 degrees and two of 45 degrees - an isosceles triangle. By Pythagoras' Theorem the square of the side of the hypotenuse is equal to the sum of the squares of the other two sides (for example 25 = 16 + 9 in a triangle with sides 5, 4 and 3).

In this case the length of the hypotenuse is unknown but we know how far to the right and down we want to move - in this case 5 units of turtle travel - which gives the length of two of the sides of the triangle. The length of the third side, the hypotenuse, is found from:

square of hypotenuse = square of side a plus square of side b

or: the square root of (side a squared plus side b squared)

or, in this case: the square root of (5 squared + 5 squared)

Thus we can calculate the forward distance to move the turtle. The turtle currently points upwards so to move right and down it must turn through an angle of 90 + 45 = 135 degrees.

 
TO SQUARE :LENGTH
REPEAT 4 [FD :LENGTH LT 90]
RT 135 PENUP 
FD (SQRT (5 * 5 + 5 * 5)) 
LT 135 PENDOWN
SQUARE (:LENGTH + 10)
END
 

 

 

 

 

You may not understand this fully if you have not studied Pythagoras' theorem.

Solving General Right Angled Triangles

We can use trigonometry to solve and thus draw right angle triangles. First we draw sides A and B of the triangle at right angles: 

MAKE "A 70  MAKE "B 90
FD :A LT 90 FD :B 

These are the first two sides, A and B.

 

 

 

The sine of an angle is given by (Opposite/Hypotenuse), or:

angle = arcsin (O/H)

The opposite side to this angle is the side A but we do not yet know the length of the hypotenuse. To calculate it we use Pythagoras as before:

SQR (first_side squared + second_side squared)  

or:  MAKE "C=SQR (70*70 + 90*90)

or: MAKE "C=SQR(A*A + B*B)

To find the angle through which the turtle must turn to point itself at the origin of the triangle we calculate ARCSIN (OPPOSITE / HYPOTENUSE) or ARCSIN (:A/:C).

Early versions of Logo did not include the ARCSIN function which means extra work before we can draw the last side of the triangle. Without the ARCSIN function we would have to calculate its value from the mathematical series from which it is derived. Each trigonometrical function can be calculated for a given value of x from the expansion for that function. We can use an algebraic program like Maple to obtain the expansion for arcsin:

series(arcsin(x), x=0, 4)0, 4)

which gives: x + 1/6x^3 + 3/40x^5 + 5/112x^7.

 

To remind you, the value of 'x' here is O/H. The caret ('^') symbol stands for 'raise to the power'. Logo does not understand this symbol so we will have to write out the powers longhand. Four terms were specified which gives a reasonable level of accuracy but 6 or 8 or more could have been obtained. (The sequences for numerators and exponents are easy to work out, but what is the sequence for the denominators?)

Applying the series for arcsin with T substituted for x (the value of O/H):

x=T + 1/6T^3 + 3/40T^5 + 5/112T^7

or:  

x=T + 1/6*(T*T*T) + 3/40*(T*T*T*T*T)+ 5/112*(T*T*T*T*T*T*T)

This value is in radians so we convert it to degrees for Logo:

   x=x*180/pi

Logo understands ‘pi’ as 3.14159265358979.

The turtle can now be turned through the angle we have calculated: LT 180 - x    

The angle of turn is (180 - x) because the angle is acute).

Finally, we calculate the last angle and leave the turtle pointing in the original direction. The last angle is 90 - x so the angle to turn is 180 - (90 - x) or 90 + x. FD :C  LT 90 + :x

This leaves the turtle where it began.

Putting this into a procedure for easy use we have:

TO RTANGLETRI :A :B
FD :A   LT 90   FD :B
MAKE "C  SQRT (:A * :A + :B * :B)
MAKE "T :A / :C
MAKE "x  :T + 1/6*(:T*:T*:T) + 3/40*(:T*:T*:T*:T*:T) + 5/112*(:T*:T*:T*:T*:T*:T*:T)
MAKE "x :x * 180 / pi LT 180 - :x FD :C LT 90 + :x
END

 

 

 

We can use other formulae for solving right angled triangles from other points. For example, you can calculate the height of a tree from the distance A and the angle a:

  1. The distance from the tree, side A of the triangle, is measured at 90 feet
  2. The angle a is measured at 15 degrees
  3. The height is calculated from: (TAN 15) * 90 = 24.115

FD :C  LT 90 + :x

This leaves the turtle where it began.

 

 

 

 

We can verify by drawing the triangle:

FD 90 LT 90
FD 24.115
LT 105
FD SQRT(90*90+24.115*24.115)

You get the idea? It is a little long-winded compared with using a calculator but solving problems from first principles like this can teach you a lot and reinforce what you already know.

Return to Logo Home Page