Can anyone explain bezier curves in the most simple way possible please?

Hello, I am trying to understand bezier curves,

I have experimented with Bezier Curves for over 10 days now, And I still do not understand it much.

From now I have understood that t is the time, I do not understand how to interpolate through a bezier curve to a point, can someone please explain bezier curves without giving a headache.

Thanks,

5 Likes

I’ve recently watched a couple videos on Bezier curves and read some articles. I can’t really “explain” since I’m very awful at math, like I legitimately hate it, but anyways, here’s what I can tell you

This is the formula for a Quadratic Bezier curve:

B(t) = (1-t) Bp0,p1(t) + t Bp1,p2(t)

--A Quadratic Bezier has 3 control points
--t being the interval, a float between 0 and 1
--p0 being Point0 (mostly the start point) 
--p1 being the 'curve' point (this is the point which the curvature is based off)
--p2 being point2 (the end point)

--[[
    Since vector3 values can be multiplied, added, subtracted etc.
    you can just toss baseparts positions into the formula

Imagine we have 3 parts in workspace, "PartA", "PartB" and "PartC"
Let's setup the quadric bezier function
]]

local function QuadraticBezier(t,p0,p1,p2)
    return (1-t)^2*p0+2*(1-t)*t*p1+t^2*p2; --<Very simple :D
end;

local Part0 = workspace.Part0;--<Start point
local Part1 = workspace.Part1;--<'Curve' Point
local Part2 = workspace.Part2;--<End Point
local inter_PART = Instance.new("Part", workspace);--<Part To Move
--Now to call the bezier function, we can just wrap it in a for loop
for t = 0,1,0.01 do
    local TargetPosition = QuadraticBezier(t , Part0.Position, Part1.Position, Part2.Position);
    inter_PART.Position = TargetPosition;
end;

There’s also other Bezier types

  • Linear (Straight Line)

  • Cubic (Has 4 Control Points)

local function CubicBezier(t, p0, p1, p2, p3)
    return (1-t)^3*p0+3*(1-t)^2*t*p1+3*(1-t)^2*p2+t^3*p3
end;
--> EDIT ^^ should be (1-t) * t^2 * p2. Fix available below.
--> Left old incorrect formula just incase someone was previously using this as a reference.

-- FIX:
local function CubicBezier(t, p0, p1, p2, p3)
    return (1 - t) ^ 3 * p0 + 3 * (1 - t) ^ 2 * t * p1 + 3 * (1 - t) * t ^ 2 * p2 + t ^ 3 * p3
end;

Hope this helped, sorry for any errors :smiley:

46 Likes

If you haven’t yet found / read the Wikipedia page, then I suggest you take a look at it, and in particular the ‘Construction Bezier curves’ section.

The animations in that section, should give you some clue to “whats going on”, for how to make a bezier curve, from a simple one of just two points (just a straight line), then one with three points (quadratic curve), and so on.

The “t is time” is a bit misleading, as I see ‘t’ as a percentage (e.g. “offset %”) within a straight line to calculate a point to use - which will either be used as a start-or-end-point of a new straight line, or as a point on the resulting bezier curve.

Making a single bezier curve, is basically a for loop where ‘t’ starts at zero (0%) and is incremented by some fraction until it reaches one (100%), where the value of ‘t’ is used to repeatedly calculating “a point” for each “straight line”, and do that for each “new straight line” that can be made from those points, until there are no more lines to be made.

Once all the points have been calculated, then it is just a matter of “connect the dots” to get the bezier curve, which will be more or less detailed, depending on what fraction-value you used for “incrementing t”.

When you have understood these basics calculations for “new straight lines” / “the points”, and that it takes several calculations just for finding “one point”, then you will (hopefully) discover that those other strange math formulas presented, are “optimizations” for very specific types of bezier curves.

Also you might want to study this afterwards: Reparameterization: Tips and Tricks - Scripting Helpers

2 Likes

the most simple way possible

Quadratic beziers are the simplest case. Here’s a visual:

Endpoints P0 and P2. Control point P1.

Percentage t is between 0.0 and 1.0.

Get A = P0:Lerp(P1, t).

Get B = P1:Lerp(P2, t).

The green line in the gif is from A to B.

The point t-percent along the curve is then point = A:Lerp(B, t).

Edit: Cubic and higher-order beziers just have more layers of Lerping:

14 Likes

Love this simple example!

I tried a Bezier ‘module’ that was over 500 lines.

Ended up goin with THIS one though! :+1:

quick question, how come when i reach the end point i just keep moving backwards (never ending)