proiect geometrie computationala
13
Geometrie computationala (Proiect) Idu Stefan Andrei Informatica Anul I 1
-
Upload
stefan-andrei-idu -
Category
Documents
-
view
15 -
download
0
description
exerciții geometrie computationala
Transcript of proiect geometrie computationala
%Ex. 15 p 90
%Operatii de calcul si reprezentare grafica a vectorilor: suma, produs %inmultire cu scalar, produs vectorial, produs scalar, simetrii fata de %axe si puncte
% --- Executes on utton press in pus!utton1.
function pus!utton1"#allac$!O&ect, eventdata, !andles' a()* 5+
()1 10+ c() -+ d()-5 10+
v1()a1' 1' a' '+
axes!andles.axes' legend!andles.axes,!ide'
cla !old on s(
uivera1', 1', a', ',0,-,2ine3idt!,' uiverc1', d1', c', d',0,r-,2ine3idt!,4'
uiversum1,1', sum1,', sum,1', sum,',0, m-,2ine3idt!,4' legendv1,v,suma vectorilor'
vie3' grid on !old off
%uiversa1', s1', sa', s',0,m,2ine3idt!,' %uivertca1', td1', tc', td',0,g,2ine3idt!,'
%legendv1,v,v1,v-1'
% --- Executes on utton press in pus!utton. function pus!utton"#allac$!O&ect, eventdata, !andles'
a() 4+ ()5 9+
c()1 -6+ d()-* 4+
s( t(-1
uivera1', 1', a', ',0,-,2ine3idt!,' uiverc1', d1', c', d',0,r-,2ine3idt!,4'
2
uiversa1', s1', sa', s',0,m,2ine3idt!,'
%uivertca1', td1', tc', td',0,g,2ine3idt!,' legendv1,v,v1,v-1''
grid on !old off
function axes"#reate7cn!O&ect, eventdata, !andles' a() 4+ ()5 9+
c()1 -6+ d()-* 4+
!old on uivera1', 1', a', ',0'
uiverc1', d1', c', d',0' grid on axis off
!old off
% --- Executes on utton press in pus!utton4. function pus!utton4"#allac$!O&ect, eventdata, !andles'
v1() 1 4 * 4 + v() 1 0 0 * 5 +
prod8ectorial(crossv1,v'
axes!andles.axes'
legend!andles.axes,!ide' cla
!old on plot4v1:,1', v1:,', v1:,4',#olor,)0. 0.1 0.*+,2ine3idt!,'
plot4v:,1', v:,', v:,4',g,2ine3idt!,' plot4prod8ectorial:,1', prod8ectorial:,', prod8ectorial:,4', r-.,2ine3idt!,'
legendv1,v,v1,;rodusul vectorial'
vie34' !old off
% --- Executes on utton press in pus!utton*.
7unction pus!utton*"#allac$!O&ect, eventdata, !andles' v1() 1 4 * 4 + v() 1 0 0 * 5 +
prod(dotv1,v' <is a()0 0 0 prod1' prod' prod4'+
axes!andles.axes'
plot4v1:,1', v1:,', v1:,4',-,2ine3idt!,'
3
plot4v:,1', v:,', v:,4',g-,2ine3idt!,'
plot4<is a:,1', <is a:,', <is a:,4', r-.,2ine3idt!,' legendv1,v,v1,;rodusul scalar'
vie34' !old off
% --- Executes on utton press in pus!utton5. 7unction pus!utton5"#allac$!O&ect, eventdata, !andles' v1() 1 * 4+
axes!andles.axes'
legend!andles.axes,!ide' cla !old on
uiverv11,1', v11,', v1,1',0,2ine3idt!,' uiverv11,1', -v11,', v1,1',0,2ine3idt!,'
uiverv11,1', v11,', -v1,1',0,2ine3idt!,'legendv1,v,v1,;rodusul scalar'
uiverv11,1', -v11,', -v1,1',0,2ine3idt!,' legendvector,=imetrie fata de O>,=imetrie fata de Ox,=imetrie
fata de O> si Ox'
vie3'
% --- Executes on utton press in pus!utton?. 7unction pus!utton?"#allac$!O&ect, eventdata, !andles'
v1()* 4+ r()0 1+
axes!andles.axes' legend!andles.axes,!ide' cla
!old on uiver0,0,v11', v1',0,g2ine3idt!,'
plotr1', r', r,'
uiver0,0,sim1', sim',0,2ine3idt!,' legendvector v1,punctul r,vectorul simetric fata de r'
vie3' grid on
%Ex. 16 p 1* % =a se scrie o functie @atla care sa aia ca date de intrare
proiectiile % unui vector ,, u in plan <is a returneze proiectiile vectorului
% v( sim ox u.
Avem vectorul
u5,4'
sim Ox u(5,-4' sim O> u(-10,?' sim Ox -u(-10,?' sim O> u(-5,-4'
%d'
function ) xa1,>a1, x1,>1,xc1,>c1 + ( exp96supctB xa,>a,x,>,xc,>c,tx,t>'
C()1 0 tx 0 1 t> 0 0 1+ @A()xa>a1+ @D()x>1+
@#()xc>c1+
!old on plot)xa,x,xc+,)>a,>,>c+,-'
plot)xa1,x1,xc1+,)>a1,>1,>c1+, -r' !old off
Reprezentarea curbelor
%Ex p 116 supunctul a %=a se reprezinte grafic cura reprezentata de ecuatia implicita:
%xFG4/>FG4(aFG4, x,> apartin intervalului )-a,a+
a(-
t(0:0.01pi:pi x(Ht' a cost'.F4
>(Ht' a sint'.F4 plotxt',>t',r-.,line3idt!,'
grid titleAstroida' !old on
a( t(0:0.01pi:pi
x(Ht' a cost'.F4 >(Ht' a sint'.F4
plotxt',>t',-.,line3idt!,' grid
6
Polinoame Bernstein, Curbe Bezier
%Ex. p 1? gr(*' %Ieprezentati in aceeasi figura, in sugrafice diferite, pe * linii si
%* coloane aza Dernstein si aza monomiala
t(0:0.01:1
D(?1-t'.F.t.F D4(*1-t'.t.F4
D*(t.F*
!old on
suplot5,,1' plott,D0' suplot5,,4' plott,D1'
suplot5,,5' plott,D' suplot5,,6' plott,D4' suplot5,,9' plott,D*'
suplot5,,' plott,1'
suplot5,,*' plott,t' suplot5,,?' plott,t.F' suplot5,,' plott,t.F4'
suplot5,,10' plott,t.F*'
7
%Ex 1 p 145
%=crieti un program @atla care sa construiasca o figura formata din mai %multe cure Dezier - o floare- alegand corespunzator punctele de
control.
t(0:0.0001:1 D0(1-t'.F4 D1(41-t'.F.t D(41-t'.t.F' D4(t.F4 D()D0D1DD4+ 1()0 0 1.5 00 1.5 0+ ()0 1.5 00 1.5 0 0+ 4()0 1.5 00 0 -1.5 0+ *()0 1.5 0 00 -1.5 - 0+ 5()0 0 -1.5 00 - -1.5 0+ ?()0 -1.5 - 00 -1.5 0 0+ 6()0 - -1.5 00 0 1.5 0+ ()0 -1.5 0 00 1.5 0+ f1(1D f(D f4(4D f*(*D f5(5D f?(?D
8
f6(6D f(D !old on plot11,:',1,:',s' plotf11,:',f1,:',ms' plot1,:',,:',s' plotf1,:',f,:',ms' plot41,:',4,:',s' plotf41,:',f4,:',ms' plot*1,:',*,:',s' plotf*1,:',f*,:',ms' plot51,:',5,:',s' plotf51,:',f5,:',ms' plot?1,:',?,:',s' plotf?1,:',f?,:',ms' plot61,:',6,:',s' plotf61,:',f6,:',ms' plot1,:',,:',s' plotf1,:',f,:',ms' !old off
Algoritmul lui Casteljau
%Ex. 4 p 14 n(*' %Beterminarea coordonatelor punctelor de pe o cura Dezier de grad n,
prin %algoritmul lui de #astel&au si pentru reprezentarea grafica a
D()D0D1D+ ()0,1,?0,,4+
f(D t(1G4
plotf1,:',f,:',' 1(zeros,'(zeros,1'
for i(1:
plot11,:',1,:',-g' plot1,:',,:',m'
!old off
%Ex. p1*0 n(5, alt p'
%a' =e considera cunoscute coordonatele a * puncte in plan. =a se scrie % o functie care calculeaza coordonatele poligonului de control ale
curei %Dezier care trece prin aceste puncte, considerand ca punctele sunt
%repartizate ec!idistant pe cura Dezier corespunzator parametrului t % al curei'. #oordonatelep unctelor se dau intr-o matrice cu linii si
* %a'-nu merge spune ca ,,p nu e definit
function )+(exp1*0supctAp' A(1G6')6 0 0 0 1 ? 1 1 ? 1 0 0 0 6+ (A.F-1'p ( end
%' function exp1*0p' (exp1*0supctAp' for $(1:5 plotp1,$',p,$',gs' !old on end plot1,:',,:',x'
p() * ? -6 0 5 4+ (exp1*0supctAp' exp1*0p'
!old on t(0:.0001:1 D0(1-t'.F5 D1(51-t'.F*.t' D(101-t'.F4.t.F
10
D4(101-t'.F.t.F4 D*(51-t'.t.F* D5(t.F5 D()D0D1DD4D*D5+ x(D %cura Dezier interpolatoare cometx1,:',x,:'' !old off end
Interpolare F-Mill
l(zeros,n-' )a,e+(ginput1'
)c,d+(ginput1' for &(1:n-'
l:,&'(p:,&/'-p:,&' end ultim(4n-1'/1
(ones,ultim' :,1'(p:,1'
:,'()ae+ :,4'(p:,'-1G?'l:,1'
for $(1:n-4' :,4$/1'(p:,$/1' :,4$/'(p:,$/1'/1G?'l:,$'
:,4$/4'(p:,$/'-1G?'l:,$/1' end
:,4n-'/1'(p:,n-1' :,4n-'/'(p:,n-1'/1G?'l:,n-'
:,4n-'/4'()c,d+ :,ultim'(p:,n' end
%'
i(1
11
D(41-t'.t.F D4(t.F4 D()D0D1DD4+
3!ile nrJ(ng plot1,i:i/4',,i:i/4',$x-'
plotc1,:',c,:'' %cometc1,:',c,:'' nr(nr/1
i(i/4 end
%Operatii de calcul si reprezentare grafica a vectorilor: suma, produs %inmultire cu scalar, produs vectorial, produs scalar, simetrii fata de %axe si puncte
% --- Executes on utton press in pus!utton1.
function pus!utton1"#allac$!O&ect, eventdata, !andles' a()* 5+
()1 10+ c() -+ d()-5 10+
v1()a1' 1' a' '+
axes!andles.axes' legend!andles.axes,!ide'
cla !old on s(
uivera1', 1', a', ',0,-,2ine3idt!,' uiverc1', d1', c', d',0,r-,2ine3idt!,4'
uiversum1,1', sum1,', sum,1', sum,',0, m-,2ine3idt!,4' legendv1,v,suma vectorilor'
vie3' grid on !old off
%uiversa1', s1', sa', s',0,m,2ine3idt!,' %uivertca1', td1', tc', td',0,g,2ine3idt!,'
%legendv1,v,v1,v-1'
% --- Executes on utton press in pus!utton. function pus!utton"#allac$!O&ect, eventdata, !andles'
a() 4+ ()5 9+
c()1 -6+ d()-* 4+
s( t(-1
uivera1', 1', a', ',0,-,2ine3idt!,' uiverc1', d1', c', d',0,r-,2ine3idt!,4'
2
uiversa1', s1', sa', s',0,m,2ine3idt!,'
%uivertca1', td1', tc', td',0,g,2ine3idt!,' legendv1,v,v1,v-1''
grid on !old off
function axes"#reate7cn!O&ect, eventdata, !andles' a() 4+ ()5 9+
c()1 -6+ d()-* 4+
!old on uivera1', 1', a', ',0'
uiverc1', d1', c', d',0' grid on axis off
!old off
% --- Executes on utton press in pus!utton4. function pus!utton4"#allac$!O&ect, eventdata, !andles'
v1() 1 4 * 4 + v() 1 0 0 * 5 +
prod8ectorial(crossv1,v'
axes!andles.axes'
legend!andles.axes,!ide' cla
!old on plot4v1:,1', v1:,', v1:,4',#olor,)0. 0.1 0.*+,2ine3idt!,'
plot4v:,1', v:,', v:,4',g,2ine3idt!,' plot4prod8ectorial:,1', prod8ectorial:,', prod8ectorial:,4', r-.,2ine3idt!,'
legendv1,v,v1,;rodusul vectorial'
vie34' !old off
% --- Executes on utton press in pus!utton*.
7unction pus!utton*"#allac$!O&ect, eventdata, !andles' v1() 1 4 * 4 + v() 1 0 0 * 5 +
prod(dotv1,v' <is a()0 0 0 prod1' prod' prod4'+
axes!andles.axes'
plot4v1:,1', v1:,', v1:,4',-,2ine3idt!,'
3
plot4v:,1', v:,', v:,4',g-,2ine3idt!,'
plot4<is a:,1', <is a:,', <is a:,4', r-.,2ine3idt!,' legendv1,v,v1,;rodusul scalar'
vie34' !old off
% --- Executes on utton press in pus!utton5. 7unction pus!utton5"#allac$!O&ect, eventdata, !andles' v1() 1 * 4+
axes!andles.axes'
legend!andles.axes,!ide' cla !old on
uiverv11,1', v11,', v1,1',0,2ine3idt!,' uiverv11,1', -v11,', v1,1',0,2ine3idt!,'
uiverv11,1', v11,', -v1,1',0,2ine3idt!,'legendv1,v,v1,;rodusul scalar'
uiverv11,1', -v11,', -v1,1',0,2ine3idt!,' legendvector,=imetrie fata de O>,=imetrie fata de Ox,=imetrie
fata de O> si Ox'
vie3'
% --- Executes on utton press in pus!utton?. 7unction pus!utton?"#allac$!O&ect, eventdata, !andles'
v1()* 4+ r()0 1+
axes!andles.axes' legend!andles.axes,!ide' cla
!old on uiver0,0,v11', v1',0,g2ine3idt!,'
plotr1', r', r,'
uiver0,0,sim1', sim',0,2ine3idt!,' legendvector v1,punctul r,vectorul simetric fata de r'
vie3' grid on
%Ex. 16 p 1* % =a se scrie o functie @atla care sa aia ca date de intrare
proiectiile % unui vector ,, u in plan <is a returneze proiectiile vectorului
% v( sim ox u.
Avem vectorul
u5,4'
sim Ox u(5,-4' sim O> u(-10,?' sim Ox -u(-10,?' sim O> u(-5,-4'
%d'
function ) xa1,>a1, x1,>1,xc1,>c1 + ( exp96supctB xa,>a,x,>,xc,>c,tx,t>'
C()1 0 tx 0 1 t> 0 0 1+ @A()xa>a1+ @D()x>1+
@#()xc>c1+
!old on plot)xa,x,xc+,)>a,>,>c+,-'
plot)xa1,x1,xc1+,)>a1,>1,>c1+, -r' !old off
Reprezentarea curbelor
%Ex p 116 supunctul a %=a se reprezinte grafic cura reprezentata de ecuatia implicita:
%xFG4/>FG4(aFG4, x,> apartin intervalului )-a,a+
a(-
t(0:0.01pi:pi x(Ht' a cost'.F4
>(Ht' a sint'.F4 plotxt',>t',r-.,line3idt!,'
grid titleAstroida' !old on
a( t(0:0.01pi:pi
x(Ht' a cost'.F4 >(Ht' a sint'.F4
plotxt',>t',-.,line3idt!,' grid
6
Polinoame Bernstein, Curbe Bezier
%Ex. p 1? gr(*' %Ieprezentati in aceeasi figura, in sugrafice diferite, pe * linii si
%* coloane aza Dernstein si aza monomiala
t(0:0.01:1
D(?1-t'.F.t.F D4(*1-t'.t.F4
D*(t.F*
!old on
suplot5,,1' plott,D0' suplot5,,4' plott,D1'
suplot5,,5' plott,D' suplot5,,6' plott,D4' suplot5,,9' plott,D*'
suplot5,,' plott,1'
suplot5,,*' plott,t' suplot5,,?' plott,t.F' suplot5,,' plott,t.F4'
suplot5,,10' plott,t.F*'
7
%Ex 1 p 145
%=crieti un program @atla care sa construiasca o figura formata din mai %multe cure Dezier - o floare- alegand corespunzator punctele de
control.
t(0:0.0001:1 D0(1-t'.F4 D1(41-t'.F.t D(41-t'.t.F' D4(t.F4 D()D0D1DD4+ 1()0 0 1.5 00 1.5 0+ ()0 1.5 00 1.5 0 0+ 4()0 1.5 00 0 -1.5 0+ *()0 1.5 0 00 -1.5 - 0+ 5()0 0 -1.5 00 - -1.5 0+ ?()0 -1.5 - 00 -1.5 0 0+ 6()0 - -1.5 00 0 1.5 0+ ()0 -1.5 0 00 1.5 0+ f1(1D f(D f4(4D f*(*D f5(5D f?(?D
8
f6(6D f(D !old on plot11,:',1,:',s' plotf11,:',f1,:',ms' plot1,:',,:',s' plotf1,:',f,:',ms' plot41,:',4,:',s' plotf41,:',f4,:',ms' plot*1,:',*,:',s' plotf*1,:',f*,:',ms' plot51,:',5,:',s' plotf51,:',f5,:',ms' plot?1,:',?,:',s' plotf?1,:',f?,:',ms' plot61,:',6,:',s' plotf61,:',f6,:',ms' plot1,:',,:',s' plotf1,:',f,:',ms' !old off
Algoritmul lui Casteljau
%Ex. 4 p 14 n(*' %Beterminarea coordonatelor punctelor de pe o cura Dezier de grad n,
prin %algoritmul lui de #astel&au si pentru reprezentarea grafica a
D()D0D1D+ ()0,1,?0,,4+
f(D t(1G4
plotf1,:',f,:',' 1(zeros,'(zeros,1'
for i(1:
plot11,:',1,:',-g' plot1,:',,:',m'
!old off
%Ex. p1*0 n(5, alt p'
%a' =e considera cunoscute coordonatele a * puncte in plan. =a se scrie % o functie care calculeaza coordonatele poligonului de control ale
curei %Dezier care trece prin aceste puncte, considerand ca punctele sunt
%repartizate ec!idistant pe cura Dezier corespunzator parametrului t % al curei'. #oordonatelep unctelor se dau intr-o matrice cu linii si
* %a'-nu merge spune ca ,,p nu e definit
function )+(exp1*0supctAp' A(1G6')6 0 0 0 1 ? 1 1 ? 1 0 0 0 6+ (A.F-1'p ( end
%' function exp1*0p' (exp1*0supctAp' for $(1:5 plotp1,$',p,$',gs' !old on end plot1,:',,:',x'
p() * ? -6 0 5 4+ (exp1*0supctAp' exp1*0p'
!old on t(0:.0001:1 D0(1-t'.F5 D1(51-t'.F*.t' D(101-t'.F4.t.F
10
D4(101-t'.F.t.F4 D*(51-t'.t.F* D5(t.F5 D()D0D1DD4D*D5+ x(D %cura Dezier interpolatoare cometx1,:',x,:'' !old off end
Interpolare F-Mill
l(zeros,n-' )a,e+(ginput1'
)c,d+(ginput1' for &(1:n-'
l:,&'(p:,&/'-p:,&' end ultim(4n-1'/1
(ones,ultim' :,1'(p:,1'
:,'()ae+ :,4'(p:,'-1G?'l:,1'
for $(1:n-4' :,4$/1'(p:,$/1' :,4$/'(p:,$/1'/1G?'l:,$'
:,4$/4'(p:,$/'-1G?'l:,$/1' end
:,4n-'/1'(p:,n-1' :,4n-'/'(p:,n-1'/1G?'l:,n-'
:,4n-'/4'()c,d+ :,ultim'(p:,n' end
%'
i(1
11
D(41-t'.t.F D4(t.F4 D()D0D1DD4+
3!ile nrJ(ng plot1,i:i/4',,i:i/4',$x-'
plotc1,:',c,:'' %cometc1,:',c,:'' nr(nr/1
i(i/4 end