Need help understanding Bezier Curves

I figured this out, things make more sense now. Now do I just use distance to get where the part should be at during that specific time / percent?

yeah. you need to go through each point and find out what % of the total length it should be at. so if you made 100 points and you’re calculating point 40, the target is 40% of the total distance.

after that, you need to find the closest point on the list that is less than or equal to the target. so if the target was 140 it could be a point with distance 139. if you know how to use binary search, it will make it much faster, otherwise just search normally.

after that, lerp the chosen point to the point ahead of it, with a gradient of (t - d0) / (d1 - d0), where d0 is the distance of chosen point and d1 is the distance of next one.

1 Like

But why dont we just readjust all 100 points and then use those points for the bezire curve?

the way this works is it kind of uses the first one you made as a skeleton. it needs to find the closest point to the real one, then move it so it gets to the right distance.

if it didn’t use the closest one, for example it used the 40th point for the 40th readjustment, that won’t solve much because what if the chosen point was ahead of the target distance? since the points in the middle are closer together. then the point can’t lerp at all.

you can try doing it the first way yourself and you’ll see what happens.

edit: think of it like you’re trying to catch the target distance between two points that are next to each other, sometimes it might be the same pair, sometimes you have to skip a pair, because it’s uneven.

How do I get the percent though?

not sure how you are handling t

if you are using a range from 0 to 1, it’s total distance times t

if you are using a range from 0 to n points, it’s distance / n * t

Alright so do i create another loop or do it in the same one

new. do one for every target length.

what? doesn’t every point have a target point?

…yeah? however you want to say it. as long as you end up with the same number of points.

Let me try explaining this in 2D pictures!
Let’s say you have 3 points, p1, p2 and p3, and a variable t in the range from 0 to 1.
p1 being for the origin.
p2 being for the curve point.
and p3 being for the target.

Now, let’s make a straight path from p1 to p2 and another from p1 to p3, and get a point on both of them using t.

Now, let’s create another path between t1 and t2 and get the point on it also using t.

t is just used to get the progression on that bezier path, and note that the bezier curve on 3 points will never touch the 2nd point, it’s just used to pull the curve.

Hope you understand =)

2 Likes

Sorry you had to write this all out but I already understand that, I just need help with arc length parameterization (sorry for misleading title of topic, that’s my fault)

How do i binary search because if I dont i have to create multiple loops which is just gonna cause more lag

you’re right about that. although, it’s a bit unrelated to to your thread topic. I’ll toss you some links since it’s pretty important.

in brief, since the distances are in order, you check the middle element’s distance. if it’s smaller than the target then do it again on the left half, if it’s bigger do it on the right half, until there’s one left.

https://rosettacode.org/wiki/Binary_search

just a heads up though, the article on the roblox wiki doesn’t actually use binary search at all as far as I can tell, just checks in order. I think it should definitely be used because it can get significantly faster.

okay then ill just make more loops because I dont really feel like doing this all for a small difference

I hope you’re not making a new loop for every point. I meant a single loop with one iteration for each :slightly_smiling_face:

you’ll need another loop inside to check for the closest point, though

I thought so lol… i almost did but then thought it over

how do I lerp it? i have the nearest point and current point. Sorry im new to linear interpolation

no problemo. lerp formula is: p0 + t * (p1 - p0)
t is a percentage between the two points, in the range 0-1.

quick summary of why this works

  • to get the direction of the vector from p0 to p1 you use p1 - p0
  • line starts at p0 so now it’s p0 + (p1 - p0). you’ll notice that just simplifies to p1, because it’s pretty much a line starting at p0 and ending at p1.
  • since it’s a certain percentage across the line starting from p0, now the equations is p0 + t * (p1 - p0) because t shortens the line starting from p0 to some location on that line.

hopefully makes sense even if you haven’t used vectors.

remember, p0 is the nearest point, p1 is the next point and t is (target - dist0) / (dist1 - dist0)

and then I what do I do with this lerp vector