BezierCurve
Represents a Bézier curve.
Properties
Points
The points of the curve.
Length
BezierCurve.Length:
number?
The approximate length of the curve. Only exists if UpdateLUT
has been called.
Functions
DeCasteljau
This is the recommended way to get a point on the curve. Uses De Casteljau's algorithm.
GetPoint
Returns a point on the curve using the explicit definition of Bézier curves, which is a bit slower than De Casteljau's algorithm.
Polynomial
Calculates the polynomial form of the curve. Returns a function, which can be used to calculate a point on the curve, and the coefficients. Since much is already precalculated, the function is good to use when you have to calculate points very often in order to save performance.
UpdateLUT
BezierCurve:
UpdateLUT
(
steps:
number?
,
calcNormals:
boolean?
) →
(
)
Updates internal lookup tables. This function should be called after you modified the points of the curve, since these tables won't be accurate anymore.
ConvertT
BezierCurve:
ConvertT
(
t:
number
--
A number between 0 and 1
) →
number
Usually the points are not evenly distributed along the curve and the t value is not equal to the length of the curve. Using arc length parameterization, the function converts a length into the time t at which this length occurs.
GetDerivative
Returns the first derivative of the curve at the time t. This is basically the direction in which the point is looking.
GetSecondDerivative
Returns the second derivative of the curve at the time t.
CreateDerivativeCurve
BezierCurve:
CreateDerivativeCurve
(
k:
number?
--
The number of the derivative, default is 1
) →
BezierCurve
Calculates the curve of a derivative.
BezierCurve:GetDerivative(t).Unit ≈ BezierCurve:CreateDerivativeCurve():GetPoint(t).Unit
GetCurvature
BezierCurve:
GetCurvature
(
t:
number
--
A number between 0 and 1
) →
number
Returns the curvature of the curve at the time t.
GetIterations
Iterates from t = 0 to 1 in the given amount of steps and passes the t value in a function in each step. By default, it uses BezierCurve:DeCasteljau. This may be useful to visualize the path of the curve or other things.
Subdivide
Subdivides the curve into two other curves.
ElevateDegree
Calculates a new curve with an elevated degree (higher amount of points). The curve itself stays unchanged.
GetExtrema
BezierCurve:
GetExtrema
(
) →
{
X:
{
number
}
,
Y:
{
number
}
,
Z:
{
number
}
}
Calculates the extrema (minimum and maximum) of the curve for every axis. They are returned as t values in an array, where the first value is the minimum and the second value the maxmimum.
In order to use this function, you have to install this complex numbers module and put it as the child of this module: https://create.roblox.com/marketplace/asset/8152231789
This is due to the fact that a numerical root-finding algorithm has to be used. In the future, I will try to remove the requirement to install it.
GetBoundingBox
BezierCurve:
GetBoundingBox
(
minimal:
boolean?
,
--
Determines if the bounding box is minimal or approximate
rotated:
boolean?
--
Determines if the minimal bounding box is rotated or axis-aligned
) →
(
)
Calculates the bounding box of the curve. By default, this is a fast approximation algorithm which returns the minimal and maximal coordinates (the corners) of an axis-aligned bounding box. Bounding boxes are typically used to make a quick exit from an algorithm to avoid doing more detailed computations. For this, they don't need to be minimal.
However, if minimal
is true, it returns the minimal and maximal coordinates
of a minimal axis-aligned bounding box.
If rotated
is true, it returns the CFrame and size,
plus the minimal and maximal coordinates of a minimal rotated bounding box.
This isn't the smallest bounding box possible, but I wasn't motivated to implement
a better algorithm because it is a lot of effort.
GetNormal
Returns 4 vectors at the given t value: the point, the derivative, the normal vector and the cross product of normal and derivative vector. This is ideal to construct a CFrame.
Clone
Clones the curve.
Destroy
BezierCurve:
Destroy
(
) →
(
)
Destroys the curve.