From d09038c44305136a06f03e22f0f9f24258a95d3d Mon Sep 17 00:00:00 2001 From: bstummer <52933850+bstummer@users.noreply.github.com> Date: Thu, 24 Nov 2022 22:23:59 +1300 Subject: [PATCH] Add GetCurvature --- src/Bezier.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Bezier.lua b/src/Bezier.lua index 5599f11..50553bb 100644 --- a/src/Bezier.lua +++ b/src/Bezier.lua @@ -2,7 +2,7 @@ Documentation: https://bstummer.github.io/bezier/ -Version of this module: 1.0.0 +Version of this module: 1.1.0 Created by Vaschex @@ -381,6 +381,16 @@ function BezierCurve:CreateDerivativeCurve(k:number?) return Bezier.new(new) end +--[=[ + Returns the curvature of the curve at the time t. + + @param t -- A number between 0 and 1 +]=] +function BezierCurve:GetCurvature(t:number):number + local d = self:GetDerivative(t) + return d:Cross(self:GetSecondDerivative(t)).Magnitude / (d.Magnitude ^ 3) +end + --[=[ Iterates from t = 0 to 1 in the given amount of steps and passes the t value in a function in each step.