Given a line with slope y/x, find a simple formula for the slope of a second line that forms a 45 degree angle with this line (find slopes for both 45 degrees more and 45 degrees less.)
This can be done without trigonometry.
Find a general formula for any angle.
This requires trigonometry.
...using complex numbers
I convert the slope into a vector in the complex plane.
let m = slope
vector = 1 + mi
Then I multiply the vector by sqrt(i), or any other vector that is 45 degrees counterclockwise from the +x direction. i+1 for instance.
(1+mi)(i+1)
=(1m) + (1+m)i
Last, I convert the vector back to a slope.
slope = (1+m)/(1m)
In the clockwise direction, 45 degrees,
(1+mi)(1i)
=(1+m) + (m1)i
slope = (m1)/(1+m)
Generally speaking, to rotate any angle (counterclockwise),
(1+mi)(cosθ+isinθ)
=(cosθmsinθ) + (mcosθ+sinθ)i
slope = (mcosθ+sinθ)/(cosθmsinθ)
And applying the magic trig identities,
(mcosθ+sinθ)/(cosθmsinθ)
= √(mē+1)sin(θarctan(1,m)) / √(mē+1)sin(θarctan(m,1))
= sin(θarctan(1,m))/sin(θarctan(m,1))
where arctan(a,b) is the generalized form of arctan(a/b)
Actually, on second thought, the previous equation is better.

Posted by Tristan
on 20060321 19:25:34 