# Linear movement over a Bézier curve

Is it possible to get a constant speed movement over a Bézier curve when its points are not kept symmetrical ?

Here white square (almost) moves at constant speed. (red and green squares are control points)

Here travel time is much longer in the green part than in the red part. (control points moved)

Curve generation and white square movement is defined as follows :

``````    public void Update(...)
{
// White square movement
_timeline += 0.01f;
if (_timeline >= 1.0f)
{
_timeline = 0.01f;
}
_timelineVector2 = GetBezierPoint(_timeline, _p0, _p1, _p2, _p3);
}

// Also used for generating curve
public static Vector2 GetBezierPoint(float t, Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3)
{
float cx = 3 * (p1.X - p0.X);
float cy = 3 * (p1.Y - p0.Y);

float bx = 3 * (p2.X - p1.X) - cx;
float by = 3 * (p2.Y - p1.Y) - cy;

float ax = p3.X - p0.X - cx - bx;
float ay = p3.Y - p0.Y - cy - @by;

float Cube = t * t * t;
float Square = t * t;

float resX = (ax * Cube) + (bx * Square) + (cx * t) + p0.X;
float resY = (ay * Cube) + (@by * Square) + (cy * t) + p0.Y;

return new Vector2(resX, resY);
}
``````
-
okay what should I do ? delete the question ? –  Aybe May 28 '12 at 0:11
(Dunno how my previous comment disappeared, this is possibly a duplicate of that). I flagged your question for moderators' attention, if they agrees they'll close it in a while; so you don't have to do anything. Anyways, very good question, it's a very common trap in gameplay programming. Next time, just search a bit before posting ;) –  Laurent Couvidou May 28 '12 at 1:02
Yes you're right :) –  Aybe May 28 '12 at 3:40
Should close soon. The white rabbit says "arc length parametrization" and that leads you down the rabbit hole, if you want to read up on the math later. –  Patrick Hughes May 28 '12 at 15:31
Definitely ! ^_^ –  Aybe May 29 '12 at 20:24