Point to point

Prerequisite

What students should know before

  • trigonometric functions

  • information about the coordinate system

  • Pythagorean theorem

  • topic: Circle and its application (program presented in this topic is necessary for this lesson),

  • Related topics: The conic sections

Time constraints:

  • starting from 90 min - double lesson

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 (I’ll refer to as the Base Unit).

Effects

Mathematics - In this lesson you will use information about the coordinate system, distance between two points, vectors, trigonometric functions.

Computer science - These lessons told you how to create the program to plot graphs of functions, to prepare a program that allows the robot to move from point to point in the coordinate system.

Exercises

  1. Create a program to check the value of tan when the measure of angle is equal \(60,\ - 60,\ 120,\ - 120\) degrees.:math:``

  2. On piece of paper mark following points\((\sqrt{3},1),\ ( -\sqrt{3} ,1),\ (\sqrt{3}, - 1),\ ( -\sqrt{3} \ , - 1)\) in the coordinate system. Create a program to see the difference between functions: atan and atan2. As argument put \(\sqrt{3}\) or \(\sqrt{3}\)for atan function and\((\sqrt{3},1),\ ( -\sqrt{3} ,1),\ (\sqrt{3}, - 1),\ ( - \sqrt{3}\ , - 1)\) for atan2.

  3. Create a program that will cause the robot to move from point (0,0) to any other point in the coordinate system. To check the program result use the following pairs of points [(0.0), (10,10)], [(0.0), (-10,0)], [(0.0), (0,-10)], [(0,0),(-10,-10)] or similar.

  4. Create a program for the robot to plot the function \(y = sin\ x\)or \(y = x{}^{2}\).

Example solution

Part 1

Mathematics

In order for the robot to move from point to point in the coordinate system first it turns by a certain angle ( see Circle and its applications lesson), next it determines the segment. So we have got two problems:

  1. How to compute the angle the robot should turn around?

  2. How to compute the segment length?

Let investigate the coordinate system and the vector image18

image17

We would like that robot goes from point A to point B.

For solving the second problem we will apply the Pythagorean theorem.

image19

For solving the first problem we’ll apply trigonometric functions.

  1. THE ANGLES in math are in radian measure.

\(180{}^{\circ}\text{ }\pi\text{ radians }\)

\(\text{y }{}^{\circ}\text{ x radians}\)

so we have conversion \(y{}^{\circ} = \frac{180{}^{\circ}\text{ x}}{\pi}\) and \(x\ radians\ = \frac{y{}^{\circ}\pi}{180}\ \)

  1. According to figure no 1 we can write \(\text{tan }\alpha\ = \ \frac{y}{\text{x }} = \frac{\left| by_{} - a_{y} \right|}{\left| b_{x} - a_{x} \right|}\).

  2. For extending these definitions for an arbitrary point in the coordinate system, we can use geometrical definitions using the standard unit circle (a circle with radius 1 unit).

image0

\(\text{tan }\alpha\ = \frac{y}{\text{x }}\ (x \neq 0)\)

Determine the values ​​of the trigonometric functions of the following angles.

\(tan\ (60{}^{0}) = tan\ (\ \frac{\pi}{3})\ = \sqrt{3}\)

\(tan\ ( - 120{}^{0}) = tan\ ( - \frac{2\pi}{3})\ = \ - tan(\pi - \frac{\pi}{3}) = tan(\frac{\pi}{3}) = \sqrt{3}\)

\(tan\ ( - 60{}^{0}) = tan\ (\ \frac{\pi}{- 3})\ = - \sqrt{3}\)

\(tan\ (120{}^{0}) = tan\ (\ \frac{2\pi}{3})\ = \ tan(\pi - \frac{\pi}{3}) = \ - tan(\frac{\pi}{3}) = - \sqrt{3}\)

We see that for different angles we obtain the same value. So can we get the angle value when we give the tangent value? Let’s look at the function \(y = tan\ x\ \)plot. We can take the inverse function to \(y = \ tan\ x\)only in the interval \((\frac{- \pi}{2},\frac{\pi}{2})\ \).

image1image2

The arctangent is the inverse of tangent. Tangent is just a ratio, and arctangent tells what degrees (radians) that angle is. In general, if you know the trig ratio but not the angle, you can use the corresponding inverse trig function to find the angle.

Computer science

Exercise 1:

Create a program to check the value of tan when the measure of angle is equal \(60,\ - 60,\ 120,\ - 120\) degrees.

Program and results here

image3 image4

Exercise 2: Mark following points\((\sqrt{3},1),\ ( - \sqrt{3} ,1),\ (\sqrt{3}, - 1),\ ( - \sqrt{3}\ , - 1)\) in the coordinate system and next create a program to see the difference between functions: atan and atan2. As argument put :math:`` or -:math:``for atan function and \((\sqrt{3} ,1),\ ( - \sqrt{3} ,1),\ (\sqrt{3}, - 1),\ ( - \sqrt{3}, - 1)\)for atan2.

Program and results here

image5

image6

Python function atan2(y,x)returns value of \(atan(y/x)\) in radians, value between \(- \pi\) and \(\pi\) representing the angle θ made between the line segment from the origin to

P and the positive x-axis.

Exercise 3:

Create a program that will cause the robot’s to move from point (0,0) to any other point in the coordinate system. To check the program result use the following pairs of points [(0.0), (10,10)], [(0.0), (-10,0)], [(0.0), (0,-10)], [(0,0),(-10,-10)] or similar.

image20

Step 1

Mark the point in the coordinate system and mark the angle θ made between the line segment from the origin to P and the positive x-axis.

Step 2

Create a program to make the robot rotate by a given angle.

We will use the program presented in lesson Circle and its applications. Try this program with R1=0.5R track width. Why will this modification be better for us?

Program here

image7

Step 3

Create a program so that the robot moves straight by the length of the vector with the given coordinates.

Mathematics

We need to determine the number of rotations of the robot wheels (compare with lesson Circle and its applications).. The distance is equal to the circumference of the robot wheel \((2\pi r = \pi d = 17.58\ \ r\)is a radius of robot’s wheel) multiplied by the number of rotations, so

\(distance\ cm\ = \pi\text{d rotations}\) .

But on the other side the distance is equal (see theory above) \(distance\ = \sqrt{x^2 + y^2}\)

so

\(rotations = \frac{\sqrt{x^2 + y^2}}{\pi d}\)

Program here

image8

Step 4

Create a program to make the robot move from one point (0,0) to another. To check the program result use the following pairs of points [(0.0), (10,10)], [(0.0), (-10,0)], [(0.0), (0,-10)], [(0,0),(-10,-10)] or similar.

We will use the program presented in step 2 and step 3. To obtain the measure of angle we use a program from exercise 2.

Program here

image9

Part 2

Exercise 4

Create a program for the robot to plot functions \(y = sin\ x\)or \(y = x{}^{2}\).

Mathematics

Get the coordinates of two points. Determine the coordinates of the vector. Move the robot by this vector, using angle rotation and forward drive. Note when determining the rotation angle, update the designated new_ angle with the current position of the robot. Let’s make a test. Mark the points [[0,0],[10,10],[20,20],[-20,20],[0,0]] and compute vectors and angles.

image10

\(A = \lbrack 0,0\rbrack\ ,\ B = \lbrack 10,10\rbrack\ AB = \lbrack 10,10\rbrack\ \alpha = atan(10,10) = 45^{\circ}\)

\(A = \lbrack 10,10\rbrack\ ,\ B = \lbrack 20,20\rbrack\ AB = \lbrack 10,10\rbrack\ \alpha = atan(10,10) = 45^{\circ}\)but rotation is not necessary - use if conditions.

\(A = \lbrack 20,20\rbrack\ ,\ B = \lbrack - 20,20\rbrack\ AB = \lbrack - 40,0\rbrack\ \alpha = atan(0, - 40) = 180^{\circ}\)\(angle = new\_ angle\ = 45\),

\(rotations\ angle = new\_ angle - old\_ anlge = 180^{\circ} - 45^{\circ} = 135^{\circ}\) update angle \(angle = new\_ angle\ = 180\)

\(A = \lbrack - 20,20\rbrack\ ,\ B = \lbrack 0,0\rbrack\ AB = \lbrack 20, - 20\rbrack\ \alpha = atan( - 20,20) = {- 45}^{\circ}\)

\(angle = new\_ angle - old\_ anlge = \ - 45^{\circ} - 180^{\circ} = {- 225}^{\circ}\),

Program here

image11

In above program robot plots the function \(y = x{}^{2}for\ \ x = 0, - 3, - 2, - 1,0,1,2,3 \)

Summary

In this lesson, we used the distance between two points, vectors, and trigonometric functions.

Python code file (ev3dev2 library) here

image12

Robot in coordinate system.

Next Section - Robot drawn triangles