**Pythagorean theorem**¶

**Possibilities of use for motivating students or teaching
programming.**

The Lego robot shows an illustrative example of the area of squares in Pythagoras’ theorem.

**Goals:**

**Motivating the students**– revision of**Pythagorean theorem**, calculating the interior and exterior angles, two-dimensional demonstration of the ratio of areas. If a pen is used, it draws a curve of the route. Pay attention to the repetition of moves.**Learning programming in Python.**Students have to analyse the necessary moves, indicate programming steps, take positive and negative rotation into account, and think about when the pen needs to be raised or lowered. The lengths of catheti need to be adapted to the performance and size of the Lego robot.

## Preparing For This Tutorial:¶

The LEGO Mindstorm EV3 Robot that coincides with this tutorial comes from building specific sections found in the LEGO Mindstorm Education Core Set building instructions. You will need to build the main body for the robot or you could prepare your own robot - watch below (compare modul ,,Robot drawing triangles”)

Time constraints:

starting from 45 min - single lesson

## Exercise¶

The data are: the catheti in a right triangle. Write a program in which the robot draws a triangle and then three squares. Two are built on the catheti and the third on the hypotenuse.

## Theory¶

In a right triangle, a cathetus (plural: catheti), commonly known as a leg, is either of the sides that are adjacent to the right angle. It is occasionally called a “side about the right angle”. The side opposite the right angle is the hypotenuse.

Students enter the data of catheti a and b. The other necessary data are calculated by the programme, taking into account:

The length of the hypotenuse c – to calculate the length of hypotenuse use \(a^{2} + b^{2} = c^{2}\)

Interior triangle angles α and β, angles needed for rotation β1=(180 – β) and α1=(180-α), to calculate we use β=tg

^{-1}(a/b) α=90-β

Learning programming in Python:

Length of hypotenuse c – to calculate the length of hypotenuse use \(a^{2} + b^{2} = c^{2}\)

Interior triangle angles α and β, angles needed for rotation β1=(180 – β) and α1=(180-α), to calculate we use β=tg

^{-1}(a/b) α=90-β

Planning the diagram indicating programming steps and programme code:

We number the moves in the sketch chronologically when analysing movement.

Diagram of the programming steps:

->a-> distance ‘ a’ move

rot+ (angle) counterclockwise rotation

rot- (angle) clockwise rotation

Example: Programming steps – analysing movement

Robot start, ->a->, rot+( 90), ->b->, rot+(180 – β), ->c->, rot+(β), ->a->, rot+( 90), ->a->, rot+( 90), ->a->, rot-( 90), ->b->, rot+(90), ->b->, rot-+90), ->b->, rot-(90), ->c->, rot+(90), ->c->, rot+(90), ->c->

## Short help on programming¶

**Commands/functions needed for the exercise**

Programming - recommendation:

Python – radian measure is used for angles

upload appropriate libraries

```
#!/usr/bin/env python3
from ev3dev2.motor import LargeMotor, OUTPUT_A, OUTPUT_B, OUTPUT_C,
SpeedPercent, MoveTank
import math
create object;
we can manage both motors simultaneously
tank_drive = MoveTank(OUTPUT_B, OUTPUT_C)
to move forward
tank_drive.on_for_rotations(SpeedPercent(50), SpeedPercent(50), length)
```

```
#!/usr/bin/env python3
calculating the necessary values
c=math.sqrt(a*a+b*b) //we calculate the hypotenuse
beta=math.atan(a/b) //we calculate beta angle (currently in radian measure)
PI=math.pi //we convert pi into a constant
We make our work easier by using the following functions:
def forward(length): //we create a function with a parameter (length)
to move forward
tank_drive.on_for_rotations(SpeedPercent(50), SpeedPercent(50), length)
def rotate(angle,orientation): // we create a function with two parameters (angle and orientation) to rotate through a certain angle in + or – direction
tank_drive.on_for_rotations(SpeedPercent(-orientation*50), SpeedPercent(orientation*50), angle)
```

*Students write a programme on the basis of programme steps they have
planned.*

*Comment: Angles alpha, beta and gamma and lengths a, b and c have to be
multiplied by empirically defined factor in order for the rotation to be
exactly 90 degrees (not more, not less). The same needs to be taken into
account when we plan moves that make the robot return to the initial
position.*

**The conic sections**