Help With Bezier Curve

Carlos has an article on line about moving along bezier curve

http://www.carlosicaza.com/2011/04/23/moving-an-object-along-a-bezier-curve-part-i/

it is a very good article and the code is very helpful and allows the object to move along the curve in a smooth manner. Most of the process I understand; just some of the math I am a little unsure of. What I have not been able to do, using that existing code, is control the overall speed of the object. When I run the code Carlos supplied it runs smooth but at a specific speed I cannot change.

I want to be able to reduce that overall speed and have the object move slower and still be smooth. Various thing I have tried creates a rather jerky movement.

Does anyone have any insight/knowledge on how to control the overall speed of the object as it traverses the curve??? Below is the key the function that handles the movement of the object. It is called by enterFrame event.
local function moveAlongThesegment( inc )

if (bFirst == true ) then
plane = display.newImage(“f15.png”,-100,-100);
prevX = bezierSegment[1].x;
prevY = bezierSegment[1].y;
bFirst = false;
return;
end

local p = {};

p.x = bezierSegment[inc].x;
p.y = bezierSegment[inc].y;

local angle = math.atan2( p.y - prevY, p.x - prevX)
angle = angle * 180 / PIE

plane.x = p.x;
plane.y = p.y;

plane:rotate(angle-prevAngle);

prevAngle = angle;

prevY = p.y;
prevX = p.x;

end
Thanks [import]uid: 148857 topic_id: 26563 reply_id: 326563[/import]

Change your increment value - [inc]

in the original code there is a “granularity” defined - changed that.

computing the bez points is different than when drawing the line

so you can compute points that have a smaller granularity than the drawing code (that is if you draw the bez curve)

and will speed up the object.

for real ‘speed’ changes when the curve changes slope/curvature you will need to reparamaterize the t value … you will need to look at John’s paper Arc Length Parameterization of Spline Curves … found on the same blog post.

yes the carlos

[import]uid: 6 topic_id: 26563 reply_id: 107777[/import]

Ferengue,

Thanks for your help. I have changed the granularity and the inc (which I had tried previously) and it does change the overall speed, but it lacks the smoothness that occurs when I leave things exactly as Carlos had it in his sample… but that moves to fast for what I am trying to do.

It is still too jerky when I make the changes you suggested. I must still be missing something. I even watched an older video that Carlos did back in 2010 where he had a tank moving on the bezier curve… it moved much slower then the plane he uses in this sample; but it moved very smoothly.

I imagine Carlos (having stepped down at Corona) is not likely to see these forums, but just in case he still peeks in occasionally, maybe he would be so kind as to suggest what else I may have missed.

If you think of anything else that might be helpful, and feel up to passing on your wisdom, it is appreciated. But in any case, thank you much for your generous help. [import]uid: 148857 topic_id: 26563 reply_id: 107821[/import]

here is another trick - get the number of points you want to traverse (inc or granularity) then put them in a table then do a transitionto between the points at the time interval you want .

[import]uid: 6 topic_id: 26563 reply_id: 107822[/import]

do you have a video that shows the jerkiness?
[import]uid: 6 topic_id: 26563 reply_id: 107823[/import]