# Another Bezier path question

## Recommended Posts

Fr4gz0n3    109
Hi guys, i'm programming a simple slotcar game, basically i have to move an object along a Bezier path (made by a sequence of bezier curves). I've done it, but there is a problem:

Bezier curves are based on the "T" parameter, and with increments such as 0.1 there's no problem, but, because of I need to change the increment of T to change velocity, T never reaches exactly the value of 1, so when the next curve starts there is a gap and an annoying stuttering in the animation.

Can anyone help me? Edited by Fr4gz0n3

##### Share on other sites
If the curves are continuous (which you can arrange by equating however many derivatives as is appropriate for the level of 'smoothness' you want and solving the resulting system of equations) and you carry whatever is left of any step into the next curve, the joins should be imperceptible.

##### Share on other sites
Xashmi    115
As TheUnbeliever says, you need to carry over a fraction of the increment to the next curve. Say you increment by 0.3, then the T values for your first curve will be 0, 0.3, 0.6, and 0.9. The second will be 0.2, 0.5, and 0.8. The third 0.1, 0.4, 0.7 and so on.

A simple formula would be

T = T_global - floor(T_global);

Where you increment T_global instead of T, just remember to keep track of which curve you are on.

##### Share on other sites
Fr4gz0n3    109
I tried, but the amount of T in one curve corresponds to different lenght in the next curve, because a tried to keep constant speed in every parts even if they have different lenght.

Edit:

maybe I forgot a part:
the increment in every part is T+=1/Curve_lenght, so in a curve T increment can be 2 units and in another one can be 5 units. Edited by Fr4gz0n3

##### Share on other sites
If you do as I suggested and make sure your curves are [url="http://en.wikipedia.org/wiki/Parametric_continuity#Parametric_continuity"]continuous[/url], you should get what you want. [i]Assuming I've done things right[/i], I get C[sub]2 [/sub]continuity between curves p and q (i.e. position, velocity and acceleration continuous across the join) requiring:

q[sub]0[/sub] = p[sub]3[/sub]
q[sub]1[/sub] = 2p[sub]3[/sub] - p[sub]2[/sub]
q[sub]2[/sub] = p[sub]1[/sub] - 4p[sub]2[/sub] + 4p[sub]3[/sub]

Working:
[spoiler]p(t) = (1-t)[sup]3[/sup]p0 + 3t(1-t)[sup]2[/sup]p[sub]1[/sub] + 3t[sup]2[/sup](1-t)p[sub]2[/sub] + t[sup]3[/sup]p[sub]3[/sub]
p'(t) = -3[(t-1)[sup]2[/sup]p[sub]0[/sub] - (3t[sup]2[/sup]-4t+1)p[sub]1[/sub] + t(3t-2)p[sub]2[/sub] - t[sup]2[/sup]p[sub]3[/sub]]
p''(t) = -6[(t-1)p0 - (3t-2)p[sub]1[/sub] + (3t-1)p[sub]2[/sub] - tp[sub]3[/sub]]

C[sub]0[/sub]: p[sub]3[/sub] = q[sub]0[/sub]

C[sub]1[/sub]: p[sub]2[/sub] - p[sub]3[/sub] = q[sub]0[/sub] - q[sub]1[/sub]
p[sub]2[/sub] - 2p[sub]3[/sub] = -q[sub]1[/sub]
q[sub]1[/sub] = 2p[sub]3[/sub] - p[sub]2[/sub]

C[sub]2[/sub]: -p[sub]1[/sub] + 2p[sub]2[/sub] - p[sub]3[/sub] = -q[sub]0[/sub] + 2q[sub]1[/sub] - q[sub]2[/sub]
= -p[sub]3[/sub] + 4p[sub]3[/sub] - 2p[sub]2[/sub] - q[sub]2[/sub]

-p[sub]1[/sub] + 4p[sub]2[/sub] - 4p[sub]3[/sub] = -q[sub]2[/sub]
q[sub]2[/sub] = p[sub]1[/sub] - 4p[sub]2[/sub] + 4p[sub]3[/sub]
[/spoiler]

[quote name='Fr4gz0n3' timestamp='1339095376' post='4947129']the increment in every part is T+=1/Curve_lenght, so in a curve T increment can be 2 units and in another one can be 5 units.[/quote]

How do you determine the curve length? If you scale your steps in t by the arc length of the current curve, that should work.

##### Share on other sites
Fr4gz0n3    109
To find the curve lenght I've done an approximation because my curve are more o less arcs of a cycle with max angle of 90. So i take the first and last point, I find the point in the middle of the curve with bezier, than I calculate the cycle across the three point and the center of the cycle, in the end with arctan and Pythagoras I find leght of the arc.

About continuity, I took value from a bezier path created in blender, here an example (it's not the actual path I use, it's just for reference):

[attachment=9345:bezier example.jpg]

I think these curves are continuous, D,B and E are on the same straight line. Edited by Fr4gz0n3