Search code examples
pythonmath3d

How to redistribute points evenly over a curve


I have some arbitrary curve in 3 dimensions made up of a list of XYZ cartesian points. The points are not evenly distributed (theres a time factor). How can I 'rebuild' the curve with a given number of points that should make up the curve. I see this done in 3D modeling programs so im pretty sure its possible, I just dont know how.

enter image description here

Based on the answer, i needed it in python so i started working to convert interparc into python. I got as far as the linear interpolation. It is probably inefficient and has redundancies, but maybe it will be useful to someone http://pastebin.com/L9NFvJyA


Solution

  • I'd use interparc, a tool of mine designed to do exactly that. It fits a spline through a general space curve in 2 or more dimensions, then chooses points that are equally spaced in terms of distance along that curve. In the case of a cubic spline, the solution uses an odesolver to do what must be a numerical integration so it is a bit slower, but it is still reasonably fast. In many cases, a simple linear interpolation (as I used here) will be entirely adequate, and extremely fast.

    The curve may be completely general, even crossing over itself. I'll give a simple example for a 3-d space curve:

    t = linspace(0,1,500).^3;
    x = sin(2*pi*t);
    y = sin(pi*t);
    z = cos(3*x + y);
    plot3(x,y,z,'o')
    grid on
    box on
    view(-9,12)
    

    enter image description here

    xyzi = interparc(100,x,y,z,'lin');
    plot3(xyzi(:,1),xyzi(:,2),xyzi(:,3),'o')
    box on
    grid on
    view(-9,12)
    

    enter image description here