How do you move multiple points with a set distance (linear) between them on a non-linear spline?

119 Views Asked by At

I'm doing some things related to spline code, and I've run into a problem. Please take a quick look at the picture below. Black = spline (bezier), red circles = points on spline

Black line = bezier spline, red circles = points on spline

Imagine that the black line is my spline (bezier) and that the red circles are points on that spline. I want to move these points so that there is always a set distance in between them (the green lines), but right now, I have only managed to move them on the spline itself (the orange line). This means that on a flat piece, everything is fine (a = c), but on a piece that has a curve, it is not okay (b != d).

So how can I make it so that the linear distance between points is always the same regardless of any curves?

1

There are 1 best solutions below

0
On

It’s not clear whether or not you know the distance $k$ that you want between each pair of consecutive points. I’ll assume that you do.

Suppose you’re at a point $P$ on the curve $C(t)$ and you want to compute a point $Q$ on the curve such that $\text{dist}(P,Q)=k$. In effect, what this means is that you have to construct a circle of radius $k$ centered at $P$, and intersect this with the curve; this will give you a suitable point $Q$.

You can either find an existing curve-curve intersection function, or you can code your own. To code your own, you need to find zeros of the function $f(t)= \text{dist}(P,C(t))-k$. If your spline is cubic, then $f^2$ will be a polynomial of degree $6$, and you can find it’s roots by standard numerical methods. If $t=t_0$ is a zero, then $Q=C(t_0)$ is a suitable next point.

With either the intersection approach or the DIY approach, there might be as many as 6 possible solutions, and you’ll have to choose the one you want via some heuristic. For small values of $k$, there will typically be only two solutions, and choosing which one you want should be easier.