The following image comes from the text and is a good visual aid for the descriptions to follow.
Background
The book defines the projection of a directed segment in this way:
The projection $proj_{Ox} \overrightarrow{M_1M_2}$ of the directed segment $\overrightarrow{M_1M_2}$ onto the x-axis is the magnitude of the directed segment $\overrightarrow{M_{1x}M_{2x}}$, whose initial point $M_{1x}$ is the projection of the beginning of the segment $\overrightarrow{M_1M_2}$ and the terminating point $M_{2x}$ is the projection of the end of the segment $\overrightarrow{M_1M_2}$.
After which they establish the relation
$$ proj_{Ox} \overrightarrow{M_1M_2} = x_2 - x_1 \tag{1} $$
where $x_i$ is the coordinate of point $M_i$, for $i = 1,2$. I understand relation $(1)$.
Then they go on to establish a different formulation for $proj_{Ox} \overrightarrow{M_1M_2}$ which goes as follows:
We displace the directed segment $\overrightarrow{M_1M_2}$ parallel to itself so that its beginning coincides with some point of the x-axis (in the above figure, this point is $M_{1x}$). We designate as $\varphi$ the least angle between the direction of the x-axis and that of the segment $\overrightarrow{M_{1x}M_{2}^*}$ resulting from the indicated parallel displacement of the segment $\overrightarrow{M_1M_2}$. Note that the angle $\varphi$ is contained between $0$ and $\pi$. Then it is evident that the angle $\pi$ is acute if the direction of the segment $\overrightarrow{M_{1x}M_{2x}}$ coincides with that of $Ox$ and is obtuse if the direction of the segment $\overrightarrow{M_{1x}M_{2x}}$ is opposite to that of $Ox$.
Then they go on to say that from this, it is easy to ascertain the validity of the following new relation
$$ proj_{Ox} \overrightarrow{M_1M_2} = |{\overrightarrow{M_1M_2}}| \cos \varphi \tag{2} $$
where $|\overrightarrow{M_1M_2}|$ denotes the length of the segment $\overrightarrow{M_1M_2}$.
Question
I have no idea how they came up with $(2)$ without any more additional information. For instance, if we take $ M_{1x}M_{2x}M_2^* $ to be a right-triangle with the hypotenuse designated by the segment $\overrightarrow{M_{1x}M_{2}^*}$, then we can show that $(2)$ is true. But we are not given this information. How do we derive (2) rigorously?
