# How can I approximate a pseudo-tangent to a function that passes through an arbitrary point on the outside?

In other words, imagine that I have the function y=x^2 and I am sitting on point (1,0.4) or something, and I swing a line out clockwise from where I am sitting until it crashes against the bottom portion of the parabola. I want to figure out what that crash-point is, approximately. It may not be a perfect tangent, but close enough.

-
Uh, may I ask why you flagged your own question? – Willie Wong Jan 6 '12 at 9:11

A tangent to $y=x^2$ at $x=h$ looks like this:

$$y=h^2+2h(x-h)$$

Let $x=1$ and $y=0.4$, since you want this tangent to pass through $(1,0.4)$. You now have a quadratic equation in $h$, with solutions $h=1\pm\sqrt{\dfrac35}$. The point you want is then $\left(1-\sqrt{\dfrac35},\dfrac25\left(4-\sqrt{15}\right)\right)$:

-
The y=x^2 was an example function; what if the function is quite complex and I can't calculate its derivative cleanly? I noticed you used 2h as the derivative of h^2 (assuming) – WhatsInAName Jan 5 '12 at 1:05
Why not just ask about the function you actually have and then let's see what can be done with it... – J. M. Jan 5 '12 at 1:43

Generically: suppose your function is parametrized as $(x(t),y(t))$ (if you have the unparametrized form $y=f(x)$ then you can always parametrize it as $(t,f(t))$, but the math is a little less elegant) and you're looking for a tangent or near-tangent through a point $(x_0,y_0)$. Then the position at a given point $t_p$ is $(x_p,y_p) = (x(t_p), y(t_p))$ and the tangent is $(x'_p, y'_p) = (x'(t_p), y'(t_p))$, so the line through this point can be given by the equation $x'_p(y-y_p) = y'_p(x-x_p)$, or $y'_px-x'_py = x_py'_p-y_px'_p$ - note that this is $Ax+By+C = 0$ with $A=y'_p$, $B=-x'_p$ and $C=y_px'_p-x_py'_p$. By the formula for point-line distance, the squared distance from this line to the point $(x_0,y_0)$ is $(Ax_0 + By_0 + C)^2\over A^2+B^2$; note that this is a function of $t$ since $A$, $B$ and $C$ each are. Also, this function is manifestly non-negative (it's a square divided by a sum of two squares), and it's zero at a given $t$ exactly when the tangent line to the curve for that $t$ passes through your point. You can take minima of this function (by finding the derivative and setting it equal to zero) and evaluate the distance function at those minima to find whether it's zero, or at least close enough to for your purposes.

-