Created
April 2, 2015 15:30
-
-
Save SgtPooki/25c6a7673f6bce329798 to your computer and use it in GitHub Desktop.
Recursive Bezier function
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
var recursiveBezier = function recursiveBezier(pointArray, t) { | |
var P1; | |
var P2; | |
var inverse; | |
var length = pointArray.length; | |
if (length === 1) { | |
return pointArray[0]; | |
} else { | |
P1 = recursiveBezier(pointArray.slice(0,length-1), t) | |
P2 = recursiveBezier(pointArray.slice(1), t); | |
inverse = 1 - t; | |
return { | |
x: inverse * P1.x + t * P2.x, | |
y: inverse * P1.y + t * P2.y | |
}; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment