📜 ⬆️ ⬇️

About the rotation matrix in simple words

When Pythagoras sailed along the Yellow River, he saw a fisherman in a boat, dozing off in a conical hat and carrying a bamboo rod in the boat.

Bearing in mind that people of different mathematical backgrounds look at Habrahabr — however, the field of linear transformations may well be in whose field of interest — due to its practical significance — I will try to tell about it as much as possible.

Continue the story



The triangular outlines of the boat, hats and fishing rods over the water so amazed the philosopher and mathematician that he froze as if spellbound.

The fisherman’s fishing rod neatly hung over the surface of the Yellow River at an angle of 45 degrees.
')
Light fog spread over the water ... and suddenly - the bow. The fisherman pulled the bait, and she began to quickly gain height, the length of the fishing line (Catet A) began to grow in front of her, and the distance from the fisherman to the fishing line began to decrease (Catet B). And the most interesting thing is that the length of the fishing rod itself has not changed at all - there were no telescopic fishing rods yet - even when she described an arc in the air and turned out to be almost above the fisherman’s head, at an angle of 90 degrees. The length of the fishing line became equal to the length of the fishing pole - the reels were already there - and the distance between the fisherman and the fishing line changed to 0 , the fishing line was in the hands of the fisherman.


The last point is very important for understanding what happens when you multiply the rod vector by the rotation matrix.

Nostalgic and think further ...


Let us recall the Pythagorean theorem: the square of the length of the fishing pole is equal to the sum of the squares of the legs - the fishing line itself and the distance between the fisherman and the place where the fishing line is immersed in water - C ^ 2 = A squared + B squared.

Imagine that the length of the fishing rod is 4.2 , the length (or height above the water) of the fishing line 3 , the distance between the fisherman and the place where the fishing line is immersed in water is also 3.

Dive into the search


1) we will find how the length of the fishing line is related to the length of the fishing rod - the sine of the angle a .
2) we will find how the length of the segment between the fisherman and the place of the line submersion correlates with the length of the fishing rod - cosine a . We consider:

sin (a) = 3 / 4.2 = 0.7
cos (a) = 3 / 4.2 = 0.7

And now we argue
What happens if the leg A is divided by sin (a) ?! those.:

3 / 0.7 = 4.2

We get the length of the fishing rod - the hypotenuse.
And if we multiply the leg A by sin (a) ?!

3 * 0.7 = 2.1

Note this distance on the hypotenuse - 2.1 .


The remaining distance also accounts for - 2.1, since it is obvious:

4.2-2.1 = 2.1

This means, then as at the current time, sine and cosine divide the hypotenuse. Since the square of the hypotenuse is 4.2 * 4.2, the question is: what will happen if 4.2 is multiplied by 2.1 ?! At the very part of it, which is connected to one of the legs:

4.2 * 2.1 = 9, (root: 3)

Same for the second leg.

Found the legs. And they were convinced that since the time of Pythagoras nothing has changed.

Further


Now once again carry out multiplication of leg A by sin (a), leg B by cos (a).

3 * 0.7 = 2.1
3 * 0.7 = 2.1


Summarize:
2.1 + 2.1 = 4.2

or
3 * 0.7 + 3 * 0.7 = 4.2


Again we got a number equal to the length of the fishing pole ... and we came close to the turn matrix.

I will remind the formula



(image from Wikipedia. Link to article )

Take its lower part - getting the point y :
y = x * sin (f) + y * cos (f)

And compare with the calculations above:

3 * 0.7 + 3 * 0.7 = 4.2
y = x * sin (f) + y * cos (f)

As two drops of water. Y in our case will be equal to 4.2.
If we apply the first part of the formula to the calculations, we get:

3 * 0.7 - 3 * 0.7 = 0

In other words, it will happen like this:

x will be 0 - the fisherman will catch the line.
y will be 4.2 - the fishing line will be equal to the length of the fishing rod.

Remember, to calculate x, sine and cosine are swapped.

F in this case is equal to 45 degrees (F = 0.7) and with such an angle the sine and cosine are equal, which is convenient for an example. In other cases, obviously, the values ​​for sine and cosine will be different. For example, for 40 degrees: cosdegree (40) = 0.7660444431, sindegree (40) = 0.6427876097 (if you disagree, contact Yandex, I used its calculator).

Eventually


Applying the formula to new values ​​of x, y several times - in a cycle, we can clearly see a circle motion, each time by 45 degrees.

If it is necessary to move the fishing rod vector by one degree, then we substitute it in the formula in place of .

How is the calculation of trigonometric functions?
As is known, ready-made functions are usually used to calculate the cosine and sine of an angle. According to the link information , calculation and accuracy depend on the system. For unix systems, there are at least two options: a function written in the depths of IBM and a built-in fsin instruction in assembly language. There is also a fdlibm library with fairly visual code and comments that show that sine and cosine are calculated in this library using the number pi.

What if the author of this article invented everything?


If you have a web server and a PHP interpreter on your computer, you can experiment with the following code, which rotates the CSS div:
File index.php

Spoiler header
<?php if (isset($_GET['ok'])) { $x= $_GET['x']*cos(1)-$y=$_GET['y']*sin(1); $y= $_GET['x']*sin(1)+$y=$_GET['y']*cos(1); } ?> 

  <style> #rotation_martix { position: absolute; top: <?=$x+300?>px; left: <?=$y+300?>px; background-color: #999; width: 10px; height: 10px; } </style> 

 < div id="rotation_martix"> </ div> <form method="GET" > <input type="submit" name="ok" value="ok"> <input type="text" name="x" value="<?=$x?>"> <input type="text" name="y" value="<?=$y?>"> </form> 



If you slightly change the matrix, you can get a rotation in a spiral or make a pendulum from a point.

Source: https://habr.com/ru/post/342674/


All Articles