# Get coordinates of function based on arc length

Given a function (e.g. $f(x) = \sin(x)$) and an arc length value, I want to calculate the corresponding $x$-value to calculate the coordinates of the point, which is located on the function with the specific arc length.

Is there a possibility to do that with any function or can I just do this for specific functions?

Since the goal is to create a script/program which does this for me, a numeric solution would be good enough.

Thanks for you help!

• Are you looking for the positive $x$-coordinate corresponding to the arc length from $x=0$? If something else, you need to specify. – rogerl Sep 26 '16 at 14:37
• A more direct example: Image you are walking on a sine-wave path. After 10 meters walking on the path, you want to know at which coordinates you are standing. – Zteve Sep 26 '16 at 14:45

## 3 Answers

For any continuous function $f(x)$, the arc length from $x=0$ to $x=a$ is given by $$L(a)=\int_0^a\sqrt{1+(f'(x))^2}\ dx$$ You are happy with a numerical solution for $a=a^*$ given $L(a)=L^*$. Here is a simple (albeit rather inefficient) method that proceeds this way:

• Start with two guesses for the desired x-coordinate $a^*$, $a_0$ and $a_1$, such that $L(a_0)<L^*$ and $L(a_1)>L^*$. (Evaluating the integral that yields $L(a)$ is itself almost always done numerically.) These two guesses form an interval bracketing $a^*$.
• Look at the midpoint of this interval $a_m$ and calculate $L(a_m)$. If this is less than $L^*$, replace $a_0$ with $a_m$; if greater, replace $a_1$ with $a_m$.
• Repeat the last step until the desired precision is reached, at which point $a^*$ can be taken as the average of the interval endpoints. Compute $f(a^*)$ and you are done.

Integrating the arc length numerically is a possibility but is inconvenient as you have no control on the value of the arc length that you reach. It will return $s(x)$ for values of $x$ with a fixed increment, but you still have to invert the relation to get $x$ as a function of $s$, by interpolation.

A better way is to consider the differential equation

$$\frac{dx}{ds}=\frac1{\sqrt{1+f'^2(x)}}$$ and integrate it by your favorite method, such as Runge-Kutta. Then you can reach the values of $s$ that you want.

If you travel along the graph of $f(x)=\sin(x)$ by starting at the origin, the distance travelled when you reach $(x,\sin x)$ is given by: $$L(x)=\int_{0}^{x}\sqrt{1+\cos^2(t)}\,dt$$ that is an elliptic integral. Your problem is so equivalent to inverting an elliptic integral: that can be done in terms of Jacobi elliptic functions. In general it is not an easy task, and it is better to exploit Newton's method, as suggested in this answer to a similar question.