# Conceptually, how to deal with zero slope lines when using y=mx+b to drive other equations

I am (with wonderful help from this site) developing a number of VBA routines to drive some shape-related activity in Powerpoint. For example, I have a circle with a line segment that starts in the center of the circle, and radiates outward in a random direction.

Right now, I'm trying to determine the nearest anchor point on the circle to where the line intersects (N, NE, E, SE, S, SW, W, NW). I'm well on my way when dealing with most lines, but if the line segment is perfectly vertical ($x_2-x_1 = 0$) or horizontal ($y_2-y_1=0$) then my slope equation $\left[m = \frac{(y_2 - y_1)}{ (x_2 - x_1)}\right]$ returns either a zero numerator or denominator, and then I get stuck trying to figure out which compass point is the closest one.

Is there perhaps a better approach than using the slope of the line segment? If I have the x,y coordinate of the intersect, perhaps there is an equation that can convert that to a degree (out of $360^\circ$) and then I could find the nearest compass point with simple division?

Thanks for any advice/help, especially anything that I can easily convert into VBA code ;-)

$\arctan(y/x)$ would be an angle in radians, and you have to be careful of the signs of $y$ and $x$. Check for a function called atan2, and make sure you convert radians to degrees. The function atan2 takes care of all the special cases of zeros in the denominator and figures out the quadrants, i.e. that $(x,-y)$ is at a different angle than $(-x,y)$ even though the ratio is $-y/x$ in either case. Same goes for the pair $(x,y)$ and $(-x,-y)$.