2

I am making game in Unity engine, where car is moving along the bezier curve by percentage of bezier curve length.

On this image you can see curve with $8$ stop points (yellow spheres). Between each stop point is $20\%$ gap of total distance.

Correct stop points

On the image above everything is working correctly, but when I move handles, that the handles have different length problem occurs.

Wrong stop points

As you can see on image above, distances between stop points are not equal. It is because of my algorithm, because I am finding point of segment by multiplying segment length by interpolation $(t)$. In short problem is that: if $t=0.5$, it is not in the $50\%$ percent of the segment. As you can see on first image, stop points are in half of segment, but in the second image it is not in half of segment. This problem will be fixed, if there is some mathematical formula, how to find distance middle point.

Visualization of problem

As you can see on the image above, there are two mid points. T param mid point can be found by setting $t = 0.5$ (it is what I am doing now), but it is not half of the distance.

How can I find distance mid point (for cubic bezier curve, that have handles in different distance)?

soupless
  • 2,344
  • See https://math.stackexchange.com/questions/12186/arc-length-of-bézier-curves – lhf May 13 '21 at 10:33
  • @lhf Thank you for answer, but i am not looking for how to calulate arc length. I know how to calculate length. I want know how to find mid point. – Vít Vohralík May 13 '21 at 10:54
  • You want an arc-length parametrization that you can sample uniformly. – lhf May 13 '21 at 11:00
  • Approximate the Bezier curve with a polyline (a sequence of short line segments), and then do the mid-point calculation on the polyline. Depending on your needs, I'd guess that somewhere between 20 and 100 line segments will be adequate. – bubba May 15 '21 at 02:26
  • There's code here: https://gamedev.stackexchange.com/questions/5373/moving-ships-between-two-planets-along-a-bezier-missing-some-equations-for-acce/5427#5427 – bubba May 15 '21 at 03:13
  • @bubba Thank, you. I already did it how u said. I made 120 tiles in each segment and the I add distances of all tiles of the segment to a variable. Than I am looping through all tiles, until I find half of the distance – Vít Vohralík May 15 '21 at 12:21

0 Answers0