Using Arc-length to place points along path

136 Views Asked by At

I have a curve line with the known information

Length: 39.2366

P1 Pos: [0,0,0]
P1 Out Vec: [-10,20,0]

P2 Pos: [20,20,0]
P2 In Vec: [30,0,0]

How would i go about placing a point along the arc-length at a distance of 35 from the first point. Where if i put a point every distance of 5, they would be evenly spaced out.

I was originally taking the dist/len to find the percentage along the path, but that didn't seem to give accurate placement values. You can see i marked in Red the result of using that solution.

The green dot is placed using built in tools. The only values required by the built in tools are the following...

Length of line: 39.2365
Fraction along path: 0.892026

That then returns me a new fraction along the path which results in

0.929999

I don't understand how they are calculating this new value, I'm assuming it's using arc length to figure it out.

I'm trying to recreate that same method. It seems like this post is similar to what i want just not sure how to translate it into a working example. https://gamedev.stackexchange.com/a/5427/162083

enter image description here

2

There are 2 best solutions below

0
On

If the blue line is flexible, solutions could be infinitely many.

If another point in between say in the middle third of length is given, bezier can be solved for.

0
On

The first step is to write a function $f$ such that $f(t)$ gives you the arclength of the Bézier curve from the start point up to the point with parameter value $t$. Let’s suppose you have such a function. Then, given a desired arclength $k$, you need to find $t$ such that $f(t)=k$. This is just a root-finding problem, which you can solve using standard software. Look up root-finding algorithms like Newton-Raphson, bisection, or the secant method.

Now, how to write the function $f$. There are (at least) two possible approaches:

Numerical integration: If your curve is $C(t)$, then, by standard calculus $$ f(t) = \int_0^t \|C’(u)\|\,du $$ There is no closed-form formula for this integral, so you have to evaluate it using numerical methods.

Polyline Approximation: Compute a large number of points (a few hundred) on your Bézier curve, and join these points by straight lines, giving you a polyline approximation of the curve. Use the polyline instead of the Bézier curve in your computations. Calculating arclengths on polylines is easy, obviously. This is the approach used in the gamedev article you found.