TITLE: Distance between point and sine wave
QUESTION [6 upvotes]: I have a project where I need to know the exact minimal distance between a point $(e, f)$ and a sine wave $y = a + b\cdot\sin(cx+d)$
Is there any way of calculating this? If not, is there a way to approximate this? 
Thanks in advance!
Edit
Following Ross' and Ben's answers, The distance between a point $(e,f)$ and a sine wave $y = a + b\cdot\sin(cx+d)$ can be calculated by defining it as a distance between two points:
$$D=\sqrt{(x-e)^2+(a+b\cdot\sin(cx+d)-f)^2}$$
The $x$ where the distance is minimal can then be calculated by $E=D^2$ and then solving $E'=0$
$$E'= 2(bc\cdot\cos(cx+d)(a+b\cdot\sin(cx+d)-f)-e+x)=0$$
$$x=e-bc\cdot\cos(cx+d)(a+b\cdot\sin(cx+d)-f)$$
This last formula can only be answered exactly in certain cases.

REPLY [2 votes]: I have had success approximating the distance to the sine curve by using a Chebyshev polynomial of the first kind. These are polynomials that satisfy the following equation:
$$T_n(\cos(x)) = \cos(nx) $$
Somewhat surprisingly, functions that satisfy this equality are polynomials, and the degree is equal to the value $n$. The intuition behind the equality is that if you draw a sine wave onto the surface of a half-cylinder and project the drawing to a plane, you will have the plot for a Chebyshev polynomial. The following diagram from this source (Creative Commons Attribution 4.0 International) illustrates this transformation.

We can use the function $T_2(x) = 2x^2 - 1$ to help us approximate the distance to the sine function. Because the Chebyshev polynomials are more easily related to the cosine curve, we'll get the distance to the cosine curve instead. This is just a shifted sine, so we just need a change of coordinates.
Given a point $(s,t)$ we would like to find a point $(x,y)$ on the cosine curve with frequency $f$. We imagine that our point $(s,t)$ is sitting on the surface of the half-cylinder, together with one cycle of our cosine curve. We can map the point down to the plane, then get the closest point on the aforementioned Chebyshev polynomial $T_2$. Finding the closest point on a parabola is a solved problem in the closed form (requires the solving of a cubic equation), so we can avoid iterative methods.
Once we have the closest point on the parabola, we can map it back to the surface of the half-cylinder. This will be our approximately closest point on the surface of the cosine curve. Care must be taken when mapping back to the half-cylinder, since the closest point on the parabola may be outside the diameter of the cylinder. This can be fixed by clamping its x coordinate to the bounds. Because of this clamping, we also must recalculate the resulting y position to be on the cosine curve. The following pseudocode computes the approximate closest point:
s = sin(s*f)/f;
(x, y) = closest point on parabola 2(f*x)^2 - 1 to (s, t)
x = asin(clamp(x*f,-1.,1.))/f
y = -cos(2f*x)

Unfortunately, this estimate really only works well when near the peak of the cosine curve, and breaks down at the two opposite peaks of the cycle and begins overestimating. To avoid this problem, we can take two estimates for the two peaks on either side of the given point $(s,t)$, then take the closest point of the two.
One thing to note is because we are using $T_2$, the resulting distance will be for the curve $\cos(2fx)$. We get a doubling of the frequency. This can be resolved by simply using a change of variables.
The resulting approximation is very good, but we can use a single Newton's method step to finalize the approximation to make it even more accurate. I am doubtful that doing more than one optimization step will improve things.
I have written an article on my website describing in further detail this method. I have also implemented it on the website shadertoy.