Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Fonction Factorielle
- int fact(int n){
- if (n == 0) {
- return 1;
- }
- else {
- return n* fact(n - 1);
- }
- }
- //Calcul polynome Bernstein
- float Bernstein(int i, int n, float t){
- int factoN = fact(n);
- int factoI = fact(i);
- int factoNI = fact(n - i);
- float rest = pow(t,i) * pow((1 - t), n - i);
- return ((factoN/(factoI*factoNI))*rest);
- }
- void traceCourbeBezier(point2 tabPointControl[], int n) {
- float u = 0;
- point2 sommeBernstein = point2(0,0);
- glBegin(GL_LINE_STRIP);
- for (int i = 0; i <= 10; i++) {
- for (int j = 0; j < n; j++) {
- sommeBernstein = sommeBernstein + (tabPointControl[j] * Bernstein(j, n-1, u));
- }
- glVertex3f(sommeBernstein.x, sommeBernstein.y, 0);
- u += 0.1;
- sommeBernstein = point2(0, 0);
- }
- glEnd();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement