Sunteți pe pagina 1din 12

Conf. dr.

Marin Vlada Universitatea din Bucuresti


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.












Programul litere.cpp // utilizeaza curbe B-spline parbolice

#include<stdio.h>
#include<dos.h>
#include<graphics.h>
#include<stdlib.h>
#include<io.h>
#include<conio.h>
#include<ctype.h>


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
//-----------------------------------------------

//procedura "curba"
//-----------------------------------------------
void curba()
{
p=1.0/lung(); // pasul de discretizare
t=0;
for (ii=1;ii<=lung();ii++)
{
a=1-t;
a=(a*a)/2;
c=(t*t)/2;
b=1-a-c;
xx=round(a*(x+x1[i])+ b*(x+x1[j])+c*(x+x1[k]));
yy=getmaxy()-round(a*(y+y1[i])+b*(y+y1[j])+c*(y+y1[k]));
lineto(xx,yy);
t=t+p;
}
} //sfarsit procedura curba
//---------------------------------------------------

// procedura "litera"
//---------------------------------------------------
void litera(int x2,int y2,FILE *fp)
{

fscanf(fp,"%d",&n);
while (n !=5000)
{

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

sfasit de fisier= 5000

a.txt

15
20 7
19 2
14 0
11 2
12 3
12 9
11 14
5 17
1 13
-1 7
1 1
6 0
11 1
12 3
12 15
5000

b.txt

12
0 7
1 1
5 0
13 13
10 28
3 13
14 0
18 5
16 9
15 7
17 5
22 8
5000

c.txt

7
20 6
19 1
15 0
7 4
10 17
15 16
17 13
Conf. dr. Marin Vlada Universitatea din Bucuresti
http://www.unibuc.ro/prof/vlada_m/
5000

d.txt

13
20 7
19 2
14 0
11 2
12 3
12 8
5 16
0 7
1 1
6 0
11 1
12 3
12 45
5000

e.txt

10
0 3
1 1
5 0
13 13
10 17
3 13
14 0
18 5
16 9
15 7
5000

f.txt

15
0 3
1 1
5 0
13 13
10 28
4 13
7 4
7 -2
7 -7
7 -2
7 4
8 1
13 0
19 2
15 6
5000

Conf. dr. Marin Vlada Universitatea din Bucuresti
http://www.unibuc.ro/prof/vlada_m/
g.txt

15
11 2
12 3
12 8
5 16
0 7
1 1
6 0
11 1
12 5
12 -7
9 -10
5 -4
9 0
12 5
22 7
5000

h.txt

15
0 7
1 1
5 0
13 13
10 28
3 13
8 4
8 -2
8 4
11 8
14 4
15 3
14 0
17 0
21 5
5000

i.txt

11
1 6
2 1
5 0
9 2
11 6
11 16
11 6
10 2
15 0
19 1
20 7
5000

Conf. dr. Marin Vlada Universitatea din Bucuresti
http://www.unibuc.ro/prof/vlada_m/
j.txt

11
1 6
2 1
5 0
11 16
11 6
11 -7
9 -10
5 -4
9 0
12 5
22 7
5000


k.txt

17
0 7
1 1
5 0
13 13
10 28
3 13
8 4
8 -2
8 4
11 8
14 4
15 3
10 2
15 1
14 0
17 -1
23 5
5000


l.txt

9
0 7
1 1
5 0
13 13
10 28
3 13
14 0
18 5
22 7
5000


Conf. dr. Marin Vlada Universitatea din Bucuresti
http://www.unibuc.ro/prof/vlada_m/
m.txt

14
0 8
3 16
5 11
5 0
5 11
7 16
10 11
10 0
10 11
13 16
15 11
15 3
17 0
22 11
5000

n.txt.

10
0 8
3 16
5 11
5 0
5 11
7 16
10 11
10 3
15 0
17 11
5000

o.txt

11
10 14
14 11
12 4
8 0
2 1
0 6
2 12
4 18
12 15
8 7
25 11
5000