Tutorials › AP Calculus › Shortest Distance from a Point to a Curve

Optimization and L'Hôpital's Rule · Tutorial 404 of 999

Shortest Distance from a Point to a Curve

Set up squared distance to a curve, find and compare all valid candidates, and determine when a nearest point is actually attained.

Advanced 10 min read

What You'll Learn

  • Express the squared distance from a fixed point to a graph as a function of one variable.
  • Derive the interior critical-point equation for a nearest point.
  • Explain why minimizing squared distance gives the same nearest point as minimizing distance.
  • Compare interior candidates with endpoints and other relevant boundary points.
  • Recognize when domain conditions guarantee a minimum and when a nearest point may not exist.

Turning Nearest-Point Questions into Optimization

A point on a curve can be close to a fixed point in more than one direction: both its horizontal and vertical coordinates matter. The distance formula combines those differences, and calculus can help locate the point or points with the smallest distance.

Suppose the curve is the graph \(y=f(x)\), with \(x\) restricted to a domain \(D\), and the fixed point is \(P=(a,b)\). The point on the graph corresponding to \(x\) is \((x,f(x))\). Its distance from \(P\) is

$$ d(x)=\sqrt{(x-a)^2+(f(x)-b)^2}. $$

Rather than differentiate this square root, we can minimize its square. This makes the optimization simpler without changing which point is closest.

Definition: The squared distance from \(P=(a,b)\) to the point \((x,f(x))\) on the graph is $$ S(x)=(x-a)^2+(f(x)-b)^2,\qquad x\in D. $$ A nearest point on the graph is a point \((x,f(x))\) for which \(S(x)\) is as small as possible over all \(x\in D\).

Why Squared Distance Gives the Same Answer

Distance is nonnegative, and the square-root function is strictly increasing on nonnegative numbers. Therefore, if one point has smaller squared distance than another, it also has smaller distance; conversely, smaller distance means smaller squared distance. The values of the minimum are different—the minimum distance is the square root of the minimum squared distance—but the minimizing point or points are the same.

Key result: To find the nearest point on a graph, minimize \(S(x)\), not \(d(x)\). Once the minimum value \(S_{\min}\) is known, the minimum distance is \(\sqrt{S_{\min}}\).

If \(f\) is differentiable at an interior point \(x\) of the domain and \(S\) has a local minimum there, Fermat’s theorem says \(S'(x)=0\). Differentiating the squared-distance expression gives the equation used to find interior candidates:

$$ S'(x)=2(x-a)+2(f(x)-b)f'(x). $$

Thus, at a differentiable interior minimum,

$$ (x-a)+(f(x)-b)f'(x)=0. $$

This equation identifies possible interior minima; it does not by itself prove that a candidate is the nearest point. Candidates must be compared, and the domain must be checked for boundaries or other places where a minimum could occur.

A Complete Candidate Check on a Closed Interval

If the allowed values of \(x\) form a closed interval \([u,v]\), and \(S\) is continuous there, the Extreme Value Theorem guarantees that \(S\) attains an absolute minimum on that interval. If \(S\) is differentiable in the interior, an absolute minimum can occur at an endpoint or at an interior point where \(S'(x)=0\). If there are interior points where \(S\) is not differentiable, those must also be checked.

1
Define the feasible domain.
Identify every value of \(x\) that corresponds to a point on the specified curve.
2
Form squared distance.
Write \(S(x)=(x-a)^2+(f(x)-b)^2\).
3
Find interior candidates.
Solve \(S'(x)=0\) at differentiable interior points, and include any interior points where \(S'\) does not exist.
4
Check boundaries.
Include endpoints that belong to the domain. For a domain with an excluded boundary, investigate what happens near it, but do not count it as an attained candidate.
5
Compare values.
Evaluate \(S\) at all valid candidates. The smallest value gives the nearest point; take its square root to obtain the distance.

Worked Example: A Parabola and a Point Above It

Worked Example: A Parabola and a Point Above It

Find the point or points on \(y=x^2\) nearest to \(P=(0,3)\).

A point on the graph is \((x,x^2)\), where \(x\in\mathbb R\). The squared distance is

$$ S(x)=(x-0)^2+(x^2-3)^2=x^2+(x^2-3)^2. $$

Differentiate using the chain rule:

$$ \begin{aligned} S'(x)&=2x+2(x^2-3)(2x)\\ &=2x+4x(x^2-3)\\ &=2x(1+2x^2-6)\\ &=2x(2x^2-5). \end{aligned} $$

Set the derivative equal to zero:

$$ 2x(2x^2-5)=0 \quad\Longrightarrow\quad x=0 \quad\text{or}\quad x=\pm\sqrt{\frac52}. $$

These are all the interior candidates. The domain is \(\mathbb R\), and \(S(x)\to\infty\) as \(|x|\to\infty\), so a minimum is attained; the candidates can be compared. At \(x=0\),

$$ S(0)=0+(0-3)^2=9. $$

At either \(x=\sqrt{5/2}\) or \(x=-\sqrt{5/2}\), we have \(x^2=5/2\), so

$$ S(x)=\frac52+\left(\frac52-3\right)^2 =\frac52+\frac14 =\frac{11}{4}. $$

Since \(11/4<9\), the nearest points are \((\sqrt{5/2},5/2)\) and \((-\sqrt{5/2},5/2)\). Each is at distance

$$ \sqrt{\frac{11}{4}}=\frac{\sqrt{11}}{2}. $$

Check: The squared distance from either listed point to \((0,3)\) is \(x^2+(x^2-3)^2=5/2+1/4=11/4\), as calculated. The two points are equally near because the graph and the fixed point are symmetric about the \(y\)-axis.

Why an Interior Candidate Must Have Zero Derivative

The candidate equation is a consequence of the ordinary local-extremum condition, not a special geometric assumption. Here is the justification. If \(x=c\) is an interior local minimum of a differentiable function \(S\), then for sufficiently small positive \(h\), \(S(c+h)-S(c)\geq 0\), while for sufficiently small negative \(h\), \(S(c+h)-S(c)\geq 0\) as well. Dividing by \(h\) reverses the inequality when \(h<0\). The right-hand difference quotients are therefore nonnegative and the left-hand ones nonpositive. If the derivative exists, the two one-sided limits agree, so their common value must be zero. Thus \(S'(c)=0\).

Applying this fact to squared distance and using the derivative already computed gives the interior candidate equation. The condition is necessary, not sufficient: a critical point could be a maximum or neither a maximum nor a minimum. That is why candidates must be compared or otherwise classified.

Worked Example: A Curve Restricted to a Segment

Worked Example: A Curve Restricted to a Segment

Find the point on the segment of \(y=2x+1\) with \(0\leq x\leq 2\) nearest to \(P=(3,0)\).

The squared distance is

$$ S(x)=(x-3)^2+(2x+1)^2,\qquad 0\leq x\leq 2. $$

Differentiate and solve for interior critical points:

$$ \begin{aligned} S'(x)&=2(x-3)+4(2x+1)\\ &=2x-6+8x+4\\ &=10x-2. \end{aligned} \qquad 10x-2=0 \quad\Longrightarrow\quad x=\frac15. $$

The point \(1/5\) lies in the interval. Check it and both endpoints:

$$ \begin{aligned} S(0)&=(-3)^2+1^2=10,\\ S\left(\frac15\right) &=\left(-\frac{14}{5}\right)^2+\left(\frac75\right)^2 =\frac{196}{25}+\frac{49}{25} =\frac{49}{5},\\ S(2)&=(-1)^2+5^2=26. \end{aligned} $$

Since \(49/5<10\) and \(49/5<26\), the minimum occurs at \(x=1/5\). The point on the segment is \((1/5,7/5)\), and its distance from \(P\) is \(\sqrt{49/5}=7/\sqrt5\).

Check: The coordinate differences are \(-14/5\) horizontally and \(7/5\) vertically. Their squared sum is \(196/25+49/25=49/5\), so the distance is \(7/\sqrt5\), as stated.

Boundaries, Unbounded Domains, and Attainment

A domain boundary matters only if it is part of the allowed curve, but an excluded boundary can still affect whether a nearest point exists. On a closed interval, check both endpoints. On a half-line such as \([1,\infty)\), check the included endpoint and any interior critical points. On an open interval, a distance may approach an infimum near an excluded endpoint without ever attaining it.

For an unbounded domain, the fact that \(S(x)\) grows without bound at infinity can help ensure that a minimum exists, but it is not enough on its own. A sufficient condition is that the domain \(D\) be nonempty and closed, that \(S\) be continuous on \(D\), and that \(S(x)\to\infty\) as \(x\) moves without bound along \(D\). To see why, choose any \(x_0\in D\). Far enough from the origin, \(S(x)>S(x_0)\). The search for a minimum can then be restricted to \(D\cap[-R,R]\) for a sufficiently large \(R\). This set is nonempty, closed, and bounded, hence compact. Continuity guarantees that \(S\) attains a minimum on it, and values outside it are larger than \(S(x_0)\), so that minimum is also a minimum on all of \(D\).

Important condition: For a continuous squared-distance function on a nonempty closed domain, growth to infinity along an unbounded domain guarantees an attained minimum. Growth at infinity alone does not rule out an excluded finite boundary where the infimum is approached but never reached.

Worked Example: An Included Endpoint Is the Nearest Point

Worked Example: An Included Endpoint Is the Nearest Point

Find the nearest point to \(P=(0,0)\) on the part of \(y=x^2\) where \(x\geq 1\).

Here \(D=[1,\infty)\), and

$$ S(x)=x^2+(x^2)^2=x^2+x^4. $$

For every \(x\geq1\), its derivative is positive:

$$ S'(x)=2x+4x^3=2x(1+2x^2)>0. $$

Thus \(S\) is increasing on the domain, so its smallest value occurs at the included endpoint \(x=1\). Direct evaluation gives \(S(1)=1+1=2\). The nearest point is \((1,1)\), and the minimum distance is \(\sqrt2\).

Check: The distance from \((1,1)\) to \((0,0)\) is \(\sqrt{1^2+1^2}=\sqrt2\). Since \(S\) increases for every allowed \(x\), no point with \(x>1\) has a smaller distance.

Common Mistake: Treating an Excluded Boundary as an Endpoint

Consider the curve \(y=0\) with domain \(x>0\), and the fixed point \(P=(0,0)\). The squared distance is \(S(x)=x^2\). It has no critical point in the domain because \(S'(x)=2x>0\) for \(x>0\). As \(x\to0^+\), \(S(x)\to0\), but \(x=0\) is not allowed. Every point on the curve has positive distance, so there is no nearest point; the distance has infimum \(0\), which is not attained.

A mistaken argument might say: “Since \(S(x)\to\infty\) as \(x\to\infty\), restrict to a large closed interval \([0,R]\); continuity then guarantees a minimum at \(x=0\).” This is wrong because the original domain is \(x>0\), not \([0,R]\). Adding \(x=0\) adds a point that is not on the specified curve. In particular, the condition \(S(x)\to\infty\) at infinity does not alone guarantee attainment when a finite boundary is excluded.

For a final check, verify the actual domain before applying an endpoint comparison or an existence argument. A boundary point can be tested as a candidate only when it belongs to the feasible domain.

Using the Method Reliably

Nearest-point problems are optimization problems with a geometric objective. The important work is not just solving a derivative equation: it is defining the exact domain, differentiating correctly, including all valid candidates, and establishing that the smallest value is actually attained. More than one nearest point is possible, as the symmetric parabola example shows.

Before finishing a solution, ask:

  • Does the squared-distance formula include both coordinate differences?
  • Did the derivative use the chain rule for \(f(x)-b\)?
  • Have all interior critical points and nondifferentiable points been considered?
  • Were included endpoints checked, and excluded boundaries kept out?
  • Does the domain or a direct comparison guarantee that the claimed minimum is attained?

Check Your Understanding

Use the squared-distance method in each question, and state which domain points must be checked.

  1. Write the squared-distance function from \((a,b)\) to a point \((x,f(x))\) on a graph.
  2. For a differentiable graph, derive the equation satisfied by any interior nearest-point candidate.
  3. Why do minimizing distance and minimizing squared distance give the same point?
  4. On a closed interval, which types of candidates must be compared to locate an absolute minimum?
  5. Why does \(S(x)\to\infty\) at infinity fail, by itself, to guarantee a nearest point on every domain?

Test yourself: AP Calculus practice exams

Ready to check what you know? Work an AP-style practice exam, then open the full solutions.

Want all 1,114 practice problems?

This tutorial covers one topic. Calc Pass covers all of AP Calculus AB & BC: full review, every practice question, and step-by-step solutions to each one.

QR code to download the Calc Pass app

Get the Calc Pass App

Scan to download and practice on the go, with instant scoring.

Calc Pass Volume 1: 1,114 Practice Questions book cover

Vol. 1: 1,114 Questions

The complete practice question bank, organized by AB & BC topic.

View on Amazon
Calc Pass Volume 2: Solutions Manual book cover

Vol. 2: Solutions Manual

Fully worked solutions to every question in Volume 1.

View on Amazon