I am wrighting some code that requires an equation that allows me to rotate a straight line about 2 coordinate points.
Basically I have a straight line ($y=mx+c$) and when I change variable $A$ the line rotates about the point $(x_1, y_1)$ and when I change variable $B$ the line rotates about point $(x_2, y_2)$.
Thanks for any help.
edit A and B are variables adjusted on a slider. They can be angle or a multiplier whichever works best for the experssion. In sumarry increasing A buy a given amount doesnt have to translate to a specific change in the position of the line.
Starting from $y=mx+c$ , rewrite it in terms of the dot product with the unit normal vector $$ \eqalign{ & \left( { - {m \over {\sqrt {1 + m^2 } }}} \right)x + \left( {{1 \over {\sqrt {1 + m^2 } }}} \right)y = {c \over {\sqrt {1 + m^2 } }} = d \cr & \quad \Downarrow \cr & {\bf x} \cdot {\bf n} = d \cr} $$
Determine the angle $\alpha$ made by $\bf n$ with the x axis (arctan in four quadrants) $$ \left\{ \matrix{ \cos \alpha = - {m \over {\sqrt {1 + m^2 } }} \hfill \cr \sin \alpha = {1 \over {\sqrt {1 + m^2 } }} \hfill \cr} \right. $$
Rewrite the same equation with reference origin translated into $P_1$ and $P2$ $$ \left\{ \matrix{ \left( {{\bf x}_1 + {\bf p}_1 } \right) \cdot {\bf n} = d\quad \Rightarrow \quad {\bf x}_1 \cdot {\bf n} = d - {\bf p}_1 \cdot {\bf n} = d_1 \hfill \cr \left( {{\bf x}_2 + {\bf p}_2 } \right) \cdot {\bf n} = d\quad \Rightarrow \quad {\bf x}_2 \cdot {\bf n} = d - {\bf p}_2 \cdot {\bf n} = d_2 \hfill \cr} \right. $$
Now, when you rotate by an angle $\beta $ the line wrt $P_1$ , you take the first expression and change the angle of $\bf n$ while keeping $d_1$ constant $$ \eqalign{ & {\bf x}_1 \cdot \left( {\cos \left( {\alpha + \beta } \right),\sin \left( {\alpha + \beta } \right)} \right) = d_1 \quad \Rightarrow \cr & \Rightarrow \quad \left( {{\bf x} - {\bf p}_1 } \right) \cdot \left( {\cos \left( {\alpha + \beta } \right),\sin \left( {\alpha + \beta } \right)} \right) = d_1 \quad \Rightarrow \cr & \Rightarrow \quad {\bf x} \cdot \left( {\cos \left( {\alpha + \beta } \right),\sin \left( {\alpha + \beta } \right)} \right) = d - {\bf p}_1 \cdot {\bf n} + {\bf p}_1 \left( {\cos \left( {\alpha + \beta } \right),\sin \left( {\alpha + \beta } \right)} \right)\quad \Rightarrow \cr & \Rightarrow \quad {\bf x} \cdot {\bf n}\left( {\alpha + \beta } \right) = d + {\bf p}_1 \cdot \left( {{\bf n}\left( {\alpha + \beta } \right) - {\bf n}\left( \alpha \right)} \right) \cr} $$
And similarly for rotating around $P_2$