When trigonometry is not needed
Theory
So, a vector (we consider only the two-dimensional case) is a pair of numbers:
Geometric meaning is a segment on a plane for which length and direction are important, but the position is not important. That is, parallel transfer does not change the vector. It is often useful to identify a vector with a point (x, y) on a plane — it's like drawing a vector from a point (0,0) to a point (x, y). Consider the basic operations.
Addition of vectors: The

geometric meaning is depicted in the picture - we move the second vector so that its beginning coincides with the end of the first, and the result is the vector from the beginning of the first to the end of the second:

Multiplying the vector by a scalar (number):

Geometric meaning - extending the vector by the appropriate number of times without changing direction (unless the opposite, if anegatively). Multiplying by -1 will flip the vector 180 ° without changing the length. Dividing a vector by a is a multiplication by 1 / a .
Scalar product of vectors:

A very important thing. Multiplying two vectors, we get a number that characterizes the length of the projection of one onto the other. By multiplying the two vectors, we can determine by sign whether the vectors are directed in one direction (the scalar product is positive), oppositely directed (the scalar product is negative) or perpendicular to each other (the product is zero). You do not need to calculate the arctangents of the coordinate relations of each vector and compare the angles. Two multiplications, one addition and one thing in a hat.
It is also important that the scalar product of the vector by itself is the square of its length (a consequence of the Pythagorean theorem):

A vector is called normalized or unit if its length is equal to unity. To normalize an arbitrary nonzero vector is to divide it by its length. This will result in a unit vector aligned with the original.
The scalar product of an arbitrary vector by a unit will give the exact length of the projection of this vector into the direction of the unit. To get not just the length, but the projection vector itself, you need to multiply this length by our unit vector:

In parentheses is the scalar product of the vectors a and e , and then the multiplication of the vector e by the scalar.
What if we need a projection onto an irregular vector? To normalize, you need to extract the root, and this is long and sad. However, if we look closely at the formula, we will understand that we need to divide the result by the square of the length, that is, simply by the scalar product of the vector by itself. That is, the projection of a onto an arbitrary nonzero b will be calculated as follows:

The scalar product of two unit vectors is the cosine of the angle between them. If suddenly you nevertheless needed an angle between the directions, check, maybe you do not need the angle at all, but its cosine (or sine, which in some cases can be obtained from the main trigonometric identity). Then you do not need to poke around with arctangents.
That, in fact, is the whole basic theory. Now try to apply it.
Reflected Ray Calculation
A reflected beam can be useful not only for optical tasks, but also, say, when modeling an elastic collision of an object with a wall, which is indispensable when programming animated beauties. Then the velocity vector of the object will change just according to the law of reflection. So, we have a falling vector l and some arbitrary straight line from which the reflection is produced. A straight line can be defined, for example, by two points. It is required to determine the reflected vector r of the same length as l :
Knowing that the angle of incidence is equal to the angle of reflection, we can come up with some kind of naive algorithm:
- Calculate the difference in the coordinates of the points of the line, take the arctangent of their relationship - we get the slope of the line to the x axis.
- Similarly determine the slope of the incident beam to the x axis.
- Calculate the difference of these angles, subtract it from 90 ° - we get the angle of incidence.
- Add the angle of incidence twice and 180 ° to the angle of inclination of the incident beam - we obtain the angle of inclination of the reflected beam.
- Calculate the length of the incident beam and multiply by the sine and cosine of the angle of inclination of the reflected beam - we get the resulting vector.
However, if you think in vectors, then a simple geometric construction gives a much faster solution:

Two projections of the vector l on the normal with a minus yes plus one more vector l will exactly give us the result:

No need to divide if the normal is already normalized. By the way, I did not tell how to determine it. If the line is defined by two points (x1, y1) and (x2, y2), then the normal vector (unnormalized) is easily defined like this:

Sometimes the normal sign is important to know which side of the line is “external”. It doesn’t matter in our task, you can easily be convinced of it.
By the way, the obtained formula of the reflected ray is also valid in the three-dimensional version, only the normal must be determined already for the plane.
Arrow drawing
Let the ends of the arrows (x1, y1) and (x2, y2) be given. We need to draw a tendril of a fixed size at the end (x2, y2). Let's look at the figure:
Here, the point (x2, y2) is denoted by the letter P. It is necessary to calculate the coordinates of points A and B in order to draw segments PA and PB. We assume that we are given the longitudinal and transverse lengths of the antennae h and w . An attentive reader can already suggest an algorithm for himself: to find the point O, subtract from P h multiplied by a unit vector along the arrow (it seems that you can’t do without a root, but you need it only once!). And then A and B are already defined, adding to O a normal vector multiplied by w and - w. Note that we did not determine the angle of the arrow anywhere (in general, this is the arctangent of the ratio of w and h ), but we do not need it: the arrow is easily drawn and so.