Created
December 9, 2017 21:51
-
-
Save EgoMoose/3468a89ca60cce4841807a48a074efe9 to your computer and use it in GitHub Desktop.
Calculates the arc length of a quadratic Bezier curve from 0 to t
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local abs = math.abs; | |
local log = math.log; | |
local sqrt = math.sqrt; | |
-- calculates length from 0 to t (where t is a percentage eg 1 = 100%). | |
local function quadraticBezierLength(t, p0, p1, p2) | |
local a = p0 - 2*p1 + p2; | |
local b = 2*(p1 - p0); | |
local A = 4*(a:Dot(a)); | |
local B = 4*(a:Dot(b)); | |
local C = b:Dot(b); | |
local q = B/(2*A); | |
local r = sqrt(C/A - q*q); | |
local tan0 = (0+q)/r; | |
local cos0 = r/sqrt((0+q)^2 + r*r); | |
local inner0 = tan0/cos0 + log(abs(tan0 + 1/cos0)); | |
local tant = (t+q)/r; | |
local cost = r/sqrt((t+q)^2 + r*r); | |
local innert = tant/cost + log(abs(tant + 1/cost)); | |
return r*r*sqrt(A)*0.5*(innert - inner0); | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment