So I got this problem:
What is the shortest distance between $f(x)=-x^3+3x^2+1$ and $g(x)=-9x+45$ on the interval $(0,+\infty)$.

Obviously I can use the distance formula here, but the point on $f(x)$ that satisfy the shortest distance ($x=3$) is also where the tangent line of $f(x)$ is parallel to $g(x)$ and the distance is their common normal. I want to prove this generally for all cases, but what happens if the two graphs don't intersect on the interval $(a,b)$, but intersect right outside the interval? Is this still true? 
Is there any condition for this to be true?
