Moving objects along curved paths using Bezier

I have now found a solution that I want to share in case someone else finds it useful. The code is derived partly from information found in the amazing guide that StarCrunch linked to above (thanks!) and the Corona tutorial that I refer to in my original post. 

Apart from creating the actual path points for the curve I also create tables with information about the transition time that should be used for a specific segment if you want constant speed. A table with rotation data is also created and should be used if you want the object to rotate so that it always has the same side facing the direction it moves.

function M.renderCurve(params) -- Set up local drawCurve = {} local t = 0 local x = 0 local y = 0 local newpoints = {} local anchorPoints = params.anchorPoints -- The anchor points to calculate the path points from local curveSegments = params.curveSegments -- The number of segments, higher number gives smoother curve local timePerSegment = params.timePerSegment -- The time to transition each segment local doRotate = params.doRotate -- If the transition object should rotate with the curve or not local curveData = {} local curvePathPoints = {} local curveSegmentTimes = {} local curveRotations = {} local calculus = {} for j = 1, (curveSegments - 1) do function drawCurve(points, t) if (#points == 1) then curvePathPoints[#curvePathPoints + 1] = { x = points[1].x, y = points[1].y } else newpoints = {} for i = 1, (#points - 1) do x = (1 - t) \* points[i].x + t \* points[i + 1].x y = (1 - t) \* points[i].y + t \* points[i + 1].y newpoints[i] = { x = x, y = y } end drawCurve(newpoints, t) end end drawCurve(anchorPoints, t) -- Update counter t = (t + (1.0 / curveSegments)) end -- The last point in the bezier curve path is the point of the last control point curvePathPoints[#curvePathPoints + 1] = { x = anchorPoints[#anchorPoints].x, y = anchorPoints[#anchorPoints].y } -- Iterate over all segments and create tables with segment time and rotation data for i = 1, #curvePathPoints - 1 do if (timePerSegment ~= nil) then calculus.xFactor = (curvePathPoints[i + 1].x - curvePathPoints[i].x) calculus.yFactor = (curvePathPoints[i + 1].y - curvePathPoints[i].y) calculus.dist = properties.definedSqrt((calculus.xFactor \* calculus.xFactor) + (calculus.yFactor \* calculus.yFactor)) curveSegmentTimes[i] = (calculus.dist \* timePerSegment) end if (doRotate) then calculus.angle = (properties.definedDeg(properties.definedAtan((curvePathPoints[i + 1].y - curvePathPoints[i].y), (curvePathPoints[i + 1].x - curvePathPoints[i].x))) + 90) calculus.angleModulo = (calculus.angle % 360) curveRotations[i] = calculus.angleModulo end end -- Add all data to master table curveData.curvePathPoints = curvePathPoints if (timePerSegment ~= nil) then curveData.curveSegmentTimes = curveSegmentTimes end if (doRotate) then curveData.curveRotations = curveRotations end -- Return master table return curveData end