http://www.unibuc.ro/prof/vlada_m/ Curbe B Curbe B Curbe B Curbe B- -- -spline si aplicatii spline si aplicatii spline si aplicatii spline si aplicatii
Fata de curbele Bezier, curbele B-spline sunt descrise prin functii polinomiale (de gr. II si III) definite pe portiuni. Curbele B-spline de gradul II (parabolice) sunt utilizate la generarea caracterelor pentru fonturile True Type ( .ttf) din sistemul Windows, iar curbele B-spline de gradul III (cubice) sunt utilizate la generarea caracterelor pentru fonturile PostScript ( .ps).
Curbele B-spline de gradul II (parabolice)
Daca se considera o linie poligonala formata din 3 puncte P i (x i , y i ), i=1,2, 3, atunci aceasta se aproximeaza cu o curba B-spline ce are o extremitate in mijlocul segmentului P 1 P 2 , iar cealalta extremitate se afla in mijlocul segmentului P 2 P 3 , curba fiind un arc de parabola (curba de gradu II) definit de drumul (aplicatia) :
: [0,1] R 2 , unde (t) = (x(t), y(t)),
x(t) = a x 1 + b x 2 + c x 3
y(t) = a y 1 + b y 2 + c y 3 , pentru t [0,1] , notatiile fiind a = (1 2t + t 2 )/2 , b = (1 + 2t -t 2 ) /2, c = t 2 /2, a+b+c = 1
P 2
P 1 P 3
Evident, pentru t=0 si t=1 avem, respectiv (0) = (x(0), y(0)), x(0) = (x 1 + x 2 )/2 , y(0) = (y 1 +y 2 )/2 si (1) = (x(1), y(1)), x(1) = (x 2 + x 3 )/2 , y(1) = (y 2 +y 3 )/2
Definitie. Linia poligonala P = P 1 P 2 ... P n , unde P i (x i , y i ), i=1,2, ,n , se aproximeaza cu o curba B-spline = 1
2 ... n-2 , avand urmatoarele proprietati ; a) are extremitatile in mijloacele segmentolor P 1 P 2 si P n-1 P n ; b) segmentele P i P i+1 , i=1,2, , n-1 sunt tangente la curba in mijloacele segmentelor P i
P i+1 . c) curba este definita pe portiuni de i : [0,1] R 2 , unde i (t) = (x(t), y(t)), i=1,2, ,n-2 si x(t) = a x i + b x i+1 + c x i+2
y(t) = a y i + b y i+1 + c y i+2 , pentru t [0,1] , notatiile fiind a = (1 2t + t 2 )/2 , b = (1 + 2t -t 2 ) /2, c = t 2 /2, a+b+c = 1 Conf. dr. Marin Vlada Universitatea din Bucuresti http://www.unibuc.ro/prof/vlada_m/
In figura urmatoare se prezinta aceste proprietati.
P 2 P 4 . . . . . P n -2 P n
1
2
3
n-2
P 1 P 3 P n -1
Programul litere.cpp realizeaza generarea literelor mari de tip rond prin citirea dintr-un fisier a unui numar de puncte ce reprezinta o linie poligonala cu punctele aflate pe conturul literei. Un exemplu de astfel de litere este prezentat mai jos.
int n,i,j,k,ii,d,max,x=1,y=450,xx,yy,x1[100],y1[100]; float a,b,c,p,t;
//functie "round" pentru rotunjire //---------------------------------------------------- int round(float nr) { int aux=nr; nr=nr*10; int val=(int)nr % 10; Conf. dr. Marin Vlada Universitatea din Bucuresti http://www.unibuc.ro/prof/vlada_m/ if (val>=0&&val<5) return aux; else return aux+1; } //sfarsit functie round //----------------------------------------------------
//functie "lung" //---------------------------------------------------- int lung() // determina numarul de diviziuni ptr. discretizare { max=0; for (int ij=i;ij<=i+1;ij++) { d =abs(x+x1[ij]-(x+x1[ij+1])); if (d>max) max=d; d=abs(y+y1[ij]-(y+y1[ij+1])); if (d>max) max=d; } return max; } //sfarsit functie lung //-----------------------------------------------
for (i=1;i<= n;i++) fscanf(fp," %d %d",&x1[i],&y1[i]);
moveto(x2+x1[1],getmaxy()-(y2+y1[1])); xx=round(((x2+x1[1])+(x2+x1[2]))/2); yy=getmaxy()-round(((y2+y1[1])+(y2+y1[2]))/2); lineto(xx, yy); for(i =1;i<=n-2;i++) Conf. dr. Marin Vlada Universitatea din Bucuresti http://www.unibuc.ro/prof/vlada_m/ { j=i+1;k=i+2; curba(); } //lineto(x2+x1[n],getmaxy()-y2+y1[n]); fscanf(fp,"%d",&n); } }//sfarsit procedura litera //-----------------------------------------------
//partea principala "main" void main(){ FILE *f; char *c; int gdriver = DETECT, gmode, errorcode,ch,bool=1,val; initgraph(&gdriver, &gmode, "d:\\borlandc\\bgi"); errorcode = graphresult(); if (errorcode != grOk) { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); }
for(int i1=1; i1<=15; i1++) { setcolor(i1); setfillstyle(1,i1); circle(i1*18,30,5); fillellipse(i1*18,30,5,5); outtextxy(i1*18-3,38,itoa(i1,c,10)); outtextxy(20,48,"Alegeti una din culorile de mai sus pentru editare prin scirerea cifrei!!!"); } gotoxy(2,5); printf("Culoare="); scanf("%d",&val); delay(4000); cleardevice(); setcolor(val); outtextxy(20,48,"Puteti incepe editarea!!!"); sleep(2); cleardevice(); while(bool) {
ch=toascii(getch()); if (!kbhit()) {
switch(ch) { case 32 : if ((x+=20)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 97 : f=fopen("d:\\borlandc\\bin\\a.txt","r"); Conf. dr. Marin Vlada Universitatea din Bucuresti http://www.unibuc.ro/prof/vlada_m/ litera(x,y,f); fclose(f); if ((x+=20)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 98 : f=fopen("d:\\borlandc\\bin\\b.txt","r"); litera(x,y,f); fclose(f); if ((x+=20)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 99 : x=x-8; f=fopen("d:\\borlandc\\bin\\c.txt","r"); litera(x,y,f); fclose(f); if ((x+=20)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 100 :f=fopen("d:\\borlandc\\bin\\d.txt","r"); litera(x,y,f); fclose(f); if ((x+=20)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 101 :f=fopen("d:\\borlandc\\bin\\e.txt","r"); litera(x,y,f); fclose(f); if ((x+=18)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 102 :f=fopen("d:\\borlandc\\bin\\f.txt","r"); litera(x,y,f); fclose(f); if ((x+=19)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 103 :f=fopen("d:\\borlandc\\bin\\g.txt","r"); litera(x,y,f); fclose(f); if ((x+=17)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 104 :f=fopen("d:\\borlandc\\bin\\h.txt","r"); litera(x,y,f); fclose(f); if ((x+=19)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 105 :f=fopen("d:\\borlandc\\bin\\i.txt","r"); litera(x,y,f); putpixel(x+11,getmaxy()-y-20,15); fclose(f); if ((x+=20)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 106 :f=fopen("d:\\borlandc\\bin\\j.txt","r"); litera(x,y,f); Conf. dr. Marin Vlada Universitatea din Bucuresti http://www.unibuc.ro/prof/vlada_m/ putpixel(x+11,getmaxy()-y-20,15); fclose(f); if ((x+=16)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 107 :f=fopen("d:\\borlandc\\bin\\k.txt","r"); litera(x,y,f); fclose(f); if ((x+=20)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 108 :f=fopen("d:\\borlandc\\bin\\l.txt","r"); litera(x,y,f); fclose(f); if ((x+=20)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 109 :f=fopen("d:\\borlandc\\bin\\m.txt","r"); litera(x,y,f); fclose(f); if ((x+=20)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 110 :f=fopen("d:\\borlandc\\bin\\n.txt","r"); litera(x,y,f); fclose(f); if ((x+=17)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 111 :f=fopen("d:\\borlandc\\bin\\o.txt","r"); litera(x,y,f); fclose(f); if ((x+=18)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 112 :f=fopen("d:\\borlandc\\bin\\p.txt","r"); litera(x,y,f); fclose(f); if ((x+=20)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 113 :f=fopen("d:\\borlandc\\bin\\q.txt","r"); litera(x,y,f); fclose(f); if ((x+=20)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 114 :f=fopen("d:\\borlandc\\bin\\r.txt","r"); litera(x,y,f); fclose(f); if ((x+=20)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 115 :f=fopen("d:\\borlandc\\bin\\s.txt","r"); litera(x,y,f); fclose(f); if ((x+=20)>getmaxx()-30) {x=1;y-=30;}; Conf. dr. Marin Vlada Universitatea din Bucuresti http://www.unibuc.ro/prof/vlada_m/ if (y<50) {cleardevice();y=450;} break; case 116 :f=fopen("d:\\borlandc\\bin\\t.txt","r"); litera(x,y,f); fclose(f); if ((x+=20)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 117 :f=fopen("d:\\borlandc\\bin\\u.txt","r"); litera(x,y,f); fclose(f); if ((x+=20)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 118 :f=fopen("d:\\borlandc\\bin\\v.txt","r"); litera(x,y,f); fclose(f); if ((x+=20)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 119 :f=fopen("d:\\borlandc\\bin\\w.txt","r"); litera(x,y,f); fclose(f); if ((x+=20)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 120 :f=fopen("d:\\borlandc\\bin\\x.txt","r"); litera(x,y,f); fclose(f); if ((x+=20)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 121 :f=fopen("d:\\borlandc\\bin\\y.txt","r"); litera(x,y,f); fclose(f); if ((x+=20)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 122 :f=fopen("d:\\borlandc\\bin\\z.txt","r"); litera(x,y,f); fclose(f); if ((x+=20)>getmaxx()-30) {x=1;y-=30;}; if (y<50) {cleardevice();y=450;} break; case 13 : x=1; if((y=y-30)<50) {cleardevice();y=450;} break; default: bool=0; }
} };
closegraph(); } Conf. dr. Marin Vlada Universitatea din Bucuresti http://www.unibuc.ro/prof/vlada_m/
Fsiere de intrare : 15 fisiere pentru generarea literelor A-O de tip rond