1// -*- mode:C++ -*- fonction de bezier f(0)=A f(1)=C f'(0)=AB f'(1)=BC qui renvoie 1 pt 2bezier3(A,B,C,x):={ 3 evalf(A*(1-x)^2+2*B*x*(1-x)+C*x^2); 4}; 5 6//dessin de la courbe en parametrique passant par A et C et tgte a AB et a BC 7courb(A,B,C):={plotparam(affixe(bezier3(A,B,C,x)),x,0,1);}; 8 9//fonction donnant le barycentre de (A1,t) et de (A2, 1-t) 10bary(A1,A2,t):={evalf(t*A2+(1-t)*A1);}; 11 12//dessin de la courbe barycentre de (courb(A1,B1,C1),t) et de (courb(A2,B2,C2),1-t) 13//on place les 6 pts puis on definit t:=element(0..1) on peut voir 14//la deformation de la courbe qd on fait varier t. 15baryc(A1,B1,C1,A2,B2,C2,t):={ 16 local M1,M2,M3; 17 M1:=bary(A1,A2,t); 18 M2:=bary(B1,B2,t); 19 M3:=bary(C1,C2,t); 20 courb(M1,M2,M3); 21}; 22 23baryl(L1,L2,t):={ 24 local L3,s1,s2; 25 s1:=size(L1); 26 s2:=size(L2); 27 if (s1 !=s2) {s1:=min(s1,s2);} 28 L3:=[]; 29 for (k:=0;k<s1;k++) { 30 L3:=append(L3,bary(L1[k],L2[k],t)); 31 } 32 return(eval(L3)); 33}; 34barycl(L1,L2,t):={evalf(t*L2+(1-t)*L1)}; 35 36bezierl(L,x):={ 37 local LS,A,B,C; 38 LS:=[]; 39 for(j:=0;j<size(L)-2;j:=j+2){ 40 A:=L[j];B:=L[j+1];C:=L[j+2]; 41 LS:=append(LS,affixe(evalf(A*(1-x)^2+2*B*x*(1-x)+C*x^2))); 42 }; 43 eval(LS); 44}; 45 46courbl(L):={ 47 local LB,LS; 48 LS:=[]; 49 LB:=bezierl(L,x); 50 //print(LB); 51 for (j:=0;j<size(LB);j:=j+1) { 52 LS:=concat(LS,plotparam(LB[j],x,0,1)); 53 //print(j,LS); 54 }; 55 return(LS); 56}; 57