today I was writing a code which takes some line equation and a circle equation,finds intersection points that are on $II$ and $III$ quadrants,draw a tangent line to circle from that point and then draws perpendicular lie to that tangent line that passes intersection point.
Here is the codes:
intersectionPoint[eqLine_, eqCircle_] :=
Module[{eq1 = eqLine, eq2 = eqCircle, pts, x1, x2, a},
pts = NSolve[eq1 && eq2, {x, y}];
x1 = x /. pts[[1]];
x2 = x /. pts[[2]];
If[x1 < 0, a = pts[[1]], a = pts[[2]]];
a];
tangentToCircle[x_, y_] :=
Module[{a = {Null, Null}},
a[[1]] = -1*(x/y);
a[[2]] = (x^2/y) + y;
a
];
perpendicular[m_, x_, y_] :=
Module[{a = {Null, Null}},
a[[1]] = (-1/m);
a[[2]] = -1*a[[1]]*x + y;
a
];
but i stopped developing when i found a problem.If a line with equation $y=0$ intersects circle,then I will get errors about division by zero in tangentToCircle function.also if a tangent line has slope of $0$ then the perpendicular function will give me similar errors.
So my questions are:
How to change my way of handling lines?(currently i just save values $m$ and $b$ for a line in $y=mx+b$ form)
How can I change a module to return different values?(for example if the slope was going to become undefined then return something )
UPDATE
here is case which I run into trouble
In[130]:= b = intersectionPoint[y == 0*x + 5, x^2 + y^2 == 25]
Out[130]= {x -> 0., y -> 5.}
In[131]:= c = tangentToCircle[x /. b, y /. b]
Out[131]= {0., 5.}
In[132]:= d = perpendicular[c[[1]], x /. b, y /. b]
During evaluation of In[132]:= Power::infy: Infinite expression 1/0. encountered. >>
During evaluation of In[132]:= Infinity::indet: Indeterminate expression 0. ComplexInfinity encountered. >>
Out[132]= {ComplexInfinity, Indeterminate}