How can I rotate $y = Kx +M$ in 90 degrees in the center of the line - not origin?

I have this equation

$$y = Kx + M$$

where $K$ is the slope and $M$ is the bias. If $K = 1$, then to turn a 90 degrees slope, then I just need to say that $K$ should be negative.

But what if $K = 0.1$, what should the negtive slope becomes then if I want the slope to be 90 degrees around the center of the line - Not the origin.

How can do that?

Update:

enter image description here

Update 2:

enter image description here


Solution 1:

If you're rotating by $90^\circ$ counter clockwise about the origin, then the image of the point $(x, y)$ on the line becomes:

$(x', y') = (-y, x) $

Thus $x = y'$ and $y = -x'$. Plug these into the equation of the line:

$(-x') = K (y') + M $

Thus

$y' = \dfrac{1}{K} (-x' - M) = - \dfrac{1}{K} x' - \dfrac{M}{K} $

Finally remove the primes from the primed variables

$y = - \dfrac{1}{K} x - \dfrac{M}{K} $

This is the equation of the rotated line.

In case you want to rotate the original line about a point $A (x_0, y_0) $ other than the origin, then the steps are modifed as follows:

The image (x', y') of a point (x, y) on the line is given by

$(x',y') = (x_0, y_0) + (- (y - y_0), (x - x_0) ) $

From which it follows that

$( x, y ) = (x_0 , y_0) + ( (y' - y_0), - (x' - x_0) ) $

Substitute this into the equation of the line

$ y_0 - (x' - x_0) = K (x_0 + (y' - y_0) ) + M $

Therefore,

$ K y' = - x' + x_0 + y_0 + K (y_0 - x_0) - M $

So that the equation of the line becomes (after removing the primes)

$ y = -\dfrac{1}{K}x + y_0 - x_0 + \dfrac{x_0 + y_0 - M}{K} $