Last active
September 5, 2015 08:02
-
-
Save melbourne2991/37930c149f2cf67a4af4 to your computer and use it in GitHub Desktop.
This file contains 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
// takes [x, y] array objects for the points | |
function bezier(t, p0, p1, p2) { | |
const ay = Math.pow(1 - t, 2) * p0[1]; | |
const by = 2 * (1 - t) * t * p1[1]; | |
const cy = Math.pow(t, 2) * p2[1]; | |
const ax = Math.pow(1 - t, 2) * p0[0]; | |
const bx = 2 * (1 - t) * t * p1[0]; | |
const cx = Math.pow(t, 2) * p2[0]; | |
const y = ay + by + cy; | |
const x = ax + bx + cx; | |
return [x, y]; | |
}; | |
function bezierCurve(p0, p1, p2, intervalSize) { | |
const curve = []; | |
for(let i = 0; i < 1; i = i + intervalSize) { | |
curve.push(bezier(i, p0, p1, p2)); | |
} | |
return curve; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment