# Evenly space points along a parametric curve?

Are there arc-length parametrization functions hidden somewhere in Sage? I have some 3D parametric curves (smooth) of length L along which I would like to put n dots at regular intervals. What I've been doing so far is using numerical integration to find the arc length parameter, and then using find_root to find the positions of the dots (spaced by arc length L/n).

This is pretty slow, and has the further limitation that I need to specify a region on which find_root should work. If the parametrization is really uneven, it's tough to develop a good initial estimate for where to look.

So, does anyone have other ideas for doing this? Thanks!

UPDATE: Here are some examples -- they're different fibers in the Hopf fibration, and are given by r = (rx,ry,rz)

Example 1:

rx(t) = -0.309*cos(t)*arccos(0.951*cos(-t - 1.57))/(sqrt(-0.904*cos(-t - 1.570)^2 + 1)*pi)
ry(t) = -0.309*sin(t)*arccos(0.951*cos(-t - 1.57))/(sqrt(-0.904*cos(-t - 1.57)^2 + 1)*pi)
rz(t) = 0.951*sin(-t - 1.57)*arccos(0.951*cos(-t - 1.57))/(sqrt(-0.904*cos(-t - 1.57)^2 + 1)*pi)]


Example 2:

rx(t) = -0.707*cos(t)*arccos(0.707*cos(-t - 1.57))/(sqrt(-0.5*cos(-t - 1.57)^2 + 1)*pi)
ry(t) = -0.707*sin(t)*arccos(0.707*cos(-t - 1.57))/(sqrt(-0.5*cos(-t - 1.57)^2 + 1)*pi)
rz(t) = 0.707*sin(-t - 1.57)*arccos(0.707*cos(-t - 1.57))/(sqrt(-0.5*cos(-t - 1.57)^2 + 1)*pi)

edit retag close merge delete

Could you give an example of a typical curve that you're considering?

( 2011-11-15 15:19:32 +0200 )edit
1

Unless a given curve has special properties (say, an ellipse) I don't know that there is a better way in general. Would it work for your needs if we did it this way but faster?

( 2011-11-16 07:39:13 +0200 )edit
1

sure, faster would definitely be good. I tried writing some cython functions myself, but couldn't really get speed improvements.

( 2011-11-16 08:09:51 +0200 )edit

Sort by » oldest newest most voted

Hi,

I used some numerical integration (by hand) and without find_roots. It works quite well and quite fast.

x(t) = 2*cos(t) - cos(2*t)
y(t) = 2*sin(t) - sin(2*t)

dx(t) = x.derivative(t)
dy(t) = y.derivative(t)

arc_length = fast_callable(sqrt(dx(t)**2 + dy(t)**2), vars=(t,), domain=RR)


First I make an approximation of the total length of my curve

total_length = 0.0
for s in xsrange(0,2*pi,0.001):
total_length += arc_length(s) * 0.001


And then it is possible to store equally spaced points (here 20)

nb_pts = 20
step = total_length / nb_pts
length = 0.
next_pt = step
L = [(x(0),y(0))]
for s in xsrange(0,2*pi,0.001):
length += arc_length(s) * 0.001
if length >= next_pt:
L.append((x(s),y(s)))
next_pt += step


And

parametric_plot((x(t),y(t)), (t,0,2*pi)) + point2d(L, color='red', pointsize=20)


more