Part of this calculation involved making a line segment for the tangent and normal lines. I wanted the segment for these lines to be a constant length. When I looked at the problem, I saw a use for polar coordinates. This is because I had a center point, and I wanted to draw a line out some constant distance outward from that point. In polar coordinates a vector is expressed as a radius from the origin, and an angle. I had the radius, I just needed direction.

The direction of this line has to come from my line equation. That equation is m x + b, where m is the slope and b is the y-intercept. The slope is expressed as rise over run, or y / x. When looking at the triangle formed from this, it was clear the angle formed were the sides opposite (rise) and adjacent (run). Opposite over adjacent is the tangent of the angle. Thus tan( θ ) = m. which means θ = tan

^{-1}( m ).

To convert back from polar coordinates we use the point ( r cos( θ ), r sin( θ ) ) where r is the radius. Plugging in the calculation for the angle θ results in ( r cos( tan

^{-1}( m ) ), r sin( tan

^{-1}( m ) ) ). With some trigonometric identities, this becomes ( r /

`√`

1+m^{2}, m r /

`√`

1+m^{2}). I could likely have figured this out using Pythagorean theorem but my method still worked.

To get the normal vector, one just has to rotates the tangent line 90 degrees. For this, some matrix math can be used, but I cheated and looked it up. Turns out to rotate a line function in the form m x + b, you just modify m such that m = -1 / m. So enjoy the demo!