Created
June 4, 2020 13:24
-
-
Save juliendargelos/f0ed1226a3d35face3fe2f9fb47a4d19 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
// Factorielle de n | |
const f = n => n === 0 ? 1 : n * f(n - 1) | |
// Coefficient binomial (nombre de parties de k éléments dans un ensemble de n éléments) | |
const c = (n, k) => f(n) / (f(k) * f(n - k)) | |
function bezier(t, points) { | |
const n = points.length - 1 | |
const o = 1 - t | |
// Somme de 0 à n du produit des polynômes de Bernstein de degré n et des coordonnées des points de contrôle | |
return points.reduce((position, point, index) => { | |
const k = c(n, index) * Math.pow(o, n - index) * Math.pow(t, index) | |
position.x += k * point.x | |
position.y += k * point.y | |
return position | |
}, { x: 0, y: 0 }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment