Finding the location of a given arc distance along a parameterized curve in python
Question: I have a parameterized 2D curve: (x,y) = f(t)

The function f is arbitrary but differentiable and hence I can figure out the
differential arc length ds along the curve at any point using standard
formulas. I can also get the total arc length S(t) from the beginning to any
point on the curve by integrating the differential arc length formula
numerically. I can control the accuracy of the calculation.

I want to find locate the point (x,y) that has a total arc length S = D from
the beginning of the curve. Even better if the implementation were in python.
I will be doing this many times, and it is part of a computational application
where I need tight control of accuracy and some confidence of convergence.

I don't know if root finding is the best approach, but my question is the
equivalent of a root finding problem for g(t) = S(t) - D where the function
g(t) is not evaluated exactly because S(t) isn't. Inexact function evaluation
messes not only with accuracy but also the monotonicity of g(t). I tried doing
tight numerical integration from the outset but it takes forever. I'm pretty
sure to converge to my required tolerance the root finding algorithm would
have to lazily control the integration accuracy as it proceeded, demanding
sloppy evaluation at the outset and increasing accuracy as the root algorithm
converges.

Is there such a thing readily available? Is there an alternative clever way to
do it?

Appreciate the help


Answer: Can you post some code, and tell us what's wrong with it?

Here is my version that calculate the t where S(t) == D:

    
    
    from scipy.integrate import quad
    from scipy.optimize import fsolve
    from math import cos, sin, sqrt, pi
    
    def circle_diff(t):
        dx = -sin(t)
        dy = cos(t)
        return sqrt(dx*dx+dy*dy)
    
    def sin_diff(t):
        dx = 1
        dy = cos(t)
        return sqrt(dx*dx+dy*dy)
    
    def curve_length(t0, S, length):
        return quad(S, 0, t0)[0] - length
    
    def solve_t(curve_diff, length):    
        return fsolve(curve_length, 0.0, (curve_diff, length))[0]
    
    print solve_t(circle_diff, 2*pi)
    print solve_t(sin_diff, 7.640395578)
    

