I have a problem in finding a rotation angle.
Given:
- Coordinates of P1
- Coordinates of P2 in unrotated state
- Slope $m$
To calculate:
- angle $\theta$ to rotate the Point P2 that the slope between P1 and P2 has a given value.
I already have a solution but this solution can be found only numerically and I need a way to find a solution without some root finding algorithm or something like this.
Here what I tried:
Formula of slope is defined as:
$$m = \frac{y_2-y_1}{x_2-x_1}$$
$x_2$ and $y_2$ can be defined as a rotation function with degree of freedom $\theta$:
$$x_2' = x_2*\cos(\theta) - y_2*\sin(\theta)$$
$$y_2' = y_2*\cos(\theta) + x_2*\sin(\theta)$$
where $x_2$ and $y_2$ are the coordinates in the unrotated (start) position and $x_2'$ and $y_2'$ are the coordinates in the searched target position.
If I put this in the equation of the slope $m$ I receive:
$$m = \frac{y_2*\cos(\theta) + x_2*\sin(\theta)-y_1}{x_2*\cos(\theta) - y_2*\sin(\theta)-x_1}$$
Since $m$ is known I can now find a solution of $\theta$.
But I solved this only with root finding algorithm and that is not what I want. Is there a way to solve this in a unique way analytically?
HINT...after rearranging you will have $$\cos\theta(mx_2-y_2)-\sin\theta(my_2+x_2)=mx_1-y_1$$ This is an equation of the form $$a\cos\theta-b\sin\theta=c$$ which can be solved by standard means such as a compound angle transformation - i.e. rewrite the left-hand side as $$R\cos(\theta+\alpha)$$