Proiect Geometrie Computationala PDF
Proiect Geometrie Computationala PDF
(Proiect)
1
Vectori
%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
axes(handles.axes2);
legend(handles.axes2,'hide')
cla
hold on
s=2;
quiver(a(1), b(1), a(2), b(2),0,'b-','Linewidth',2);
quiver(c(1), d(1), c(2), d(2),0,'r-','Linewidth',3);
quiver(sum(1,1), sum(1,2), sum(2,1), sum(2,2),0,'m-','Linewidth',3);
legend('v1','v2','suma vectorilor')
view(2)
grid on
hold off
%quiver(s*a(1), s*b(1), s*a(2), s*b(2),0,'m*','Linewidth',2);
%quiver(t*ca(1), t*d(1), t*c(2), t*d(2),0,'g*','Linewidth',2);
%legend('v1','v2','v1*2','v2*(-1)'
a=[2 3];
b=[5 9];
c=[1 -7];
d=[-4 3];
axes(handles.axes2);
legend(handles.axes2,'hide')
cla
hold on
s=2;
t=-1;
quiver(a(1), b(1), a(2), b(2),0,'b-','Linewidth',2);
quiver(c(1), d(1), c(2), d(2),0,'r-','Linewidth',3);
2
quiver(s*a(1), s*b(1), s*a(2), s*b(2),0,'m*','Linewidth',2);
%quiver(t*ca(1), t*d(1), t*c(2), t*d(2),0,'g*','Linewidth',2);
legend('v1','v2','v1*2','v2*(-1)')
grid on
hold off
axes(handles.axes2);
legend(handles.axes2,'hide')
cla
hold on
plot3(v1(:,1), v1(:,2), v1(:,3),'Color',[0.8 0.1 0.4],'Linewidth',2);
plot3(v2(:,1), v2(:,2), v2(:,3),'g','Linewidth',2);
plot3(prodVectorial(:,1), prodVectorial(:,2), prodVectorial(:,3),
‘r-.’,’Linewidth’,2);
legend(‘v1’,’v2’,’v1*2’,’Produsul vectorial’)
view(3)
hold off
axes(handles.axes2);
legend(handles.axes2,’hide’)
cla
hold on
plot3(v1(:,1), v1(:,2), v1(:,3),’b-‘,’Linewidth’,2);
3
plot3(v2(:,1), v2(:,2), v2(:,3),’g-‘,’Linewidth’,2);
plot3(<is a(:,1), <is a(:,2), <is a(:,3),’r-.’,’Linewidth’,2);
legend(‘v1’,’v2’,’v1*2’,’Produsul scalar’)
view(3)
hold off
axes(handles.axes2);
legend(handles.axes2,’hide’)
cla
hold on
quiver(v1(1,1), v1(1,2), v1(2,1),0,’Linewidth’,2);
quiver(v1(1,1), -v1(1,2), v1(2,1),0,’Linewidth’,2);
quiver(v1(1,1), v1(1,2),
-v1(2,1),0,’Linewidth’,2);legend(‘v1’,’v2’,’v1*2’,’Produsul scalar’)
quiver(v1(1,1), -v1(1,2), -v1(2,1),0,’Linewidth’,2);
legend(‘vector’,’Simetrie fata de Oy’,’Simetrie fata de Ox’,’Simetrie
fata de Oy si Ox’)
view(2)
hold off
axes(handles.axes2);
legend(handles.axes2,’hide’)
cla
hold on
quiver(0,0,v1(1), v1(2),0,’g’’Linewidth’,2);
view(2)
grid on
hold off
4
%Ex. 17 p 148
% Sa se scrie o functie Matlab care sa aiba ca date de intrare
proiectiile
% unui vector ,, u’’ in plan <is a returneze proiectiile vectorului
% v= sim ox u.
Avem vectorul
u(5,3)
sim Ox u=(5,-3)
sim Oy 2u=(-10,6)
sim Ox -2u=(-10,6)
sim Oy u=(-5,-3)
%d)
function [ xa1,ya1, xb1,yb1,xc1,yc1 ] =
ex2p97subpctD( xa,ya,xb,yb,xc,yc,tx,ty)
T=[1 0 tx; 0 1 ty; 0 0 1];
MA=[xa;ya;1];
MB=[xb;yb;1];
MC=[xc;yc;1];
MA1=T*MA;
MB1=T*MB;
MC1=T*MC;
xa1=MA1(1,1);
ya1=MA1(2,1);
xb1=MB1(1,1);
yb1=MB1(2,1);
xc1=MC1(1,1);
yc1=MC1(2,1);
hold on
plot([xa,xb,xc],[ya,yb,yc],'-b')
plot([xa1,xb1,xc1],[ya1,yb1,yc1],'-r')
hold off
5
end
>>ex2p97subpctD( 0,0,1,1,1,-1,-2,1)
Reprezentarea curbelor
a=-2;
t=0:0.01*pi:2*pi;
x=@(t) a* cos(t).^3;
y=@(t) a* sin(t).^3;
plot(x(t),y(t),'r-.','linewidth',2)
grid
title('Astroida')
hold on
a=2;
t=0:0.01*pi:2*pi;
x=@(t) a* cos(t).^3;
y=@(t) a* sin(t).^3;
plot(x(t),y(t),'b-.','linewidth',2); grid
6
Polinoame Bernstein, Curbe Bezier
t=0:0.01:1;
B0=(1-t).^4;
B1=4*(1-t).^3.*(t);
B2=6*(1-t).^2.*t.^2;
B3=4*(1-t).*t.^3;
B4=t.^4;
hold on
subplot(5,2,1); plot(t,B0)
subplot(5,2,3); plot(t,B1)
subplot(5,2,5); plot(t,B2)
subplot(5,2,7); plot(t,B3)
subplot(5,2,9); plot(t,B4)
subplot(5,2,2); plot(t,1)
subplot(5,2,4); plot(t,t)
subplot(5,2,6); plot(t,t.^2)
subplot(5,2,8); plot(t,t.^3)
subplot(5,2,10); plot(t,t.^4)
7
hold off
%Ex 12 p 135
%Scrieti un program Matlab care sa construiasca o figura formata din mai
%multe curbe Bezier - o floare- alegand corespunzator punctele de
control.
t=0:0.0001:1;
B0=(1-t).^3;
B1=3*(1-t).^2.*t;
B2=3*(1-t).*(t.^2);
B3=t.^3;
B=[B0;B1;B2;B3];
b1=[0 0 1.5 0;0 2 1.5 0];
b2=[0 1.5 2 0;0 1.5 0 0];
b3=[0 2 1.5 0;0 0 -1.5 0];
b4=[0 1.5 0 0;0 -1.5 -2 0];
b5=[0 0 -1.5 0;0 -2 -1.5 0];
b6=[0 -1.5 -2 0;0 -1.5 0 0];
b7=[0 -2 -1.5 0;0 0 1.5 0];
b8=[0 -1.5 0 0;0 1.5 2 0];
f1=b1*B;
f2=b2*B;
f3=b3*B;
f4=b4*B;
f5=b5*B;
f6=b6*B;
8
f7=b7*B;
f8=b8*B;
hold on
plot(b1(1,:),b1(2,:),'bs');
plot(f1(1,:),f1(2,:),'ms');
plot(b2(1,:),b2(2,:),'bs');
plot(f2(1,:),f2(2,:),'ms');
plot(b3(1,:),b3(2,:),'bs');
plot(f3(1,:),f3(2,:),'ms');
plot(b4(1,:),b4(2,:),'bs');
plot(f4(1,:),f4(2,:),'ms');
plot(b5(1,:),b5(2,:),'bs');
plot(f5(1,:),f5(2,:),'ms');
plot(b6(1,:),b6(2,:),'bs');
plot(f6(1,:),f6(2,:),'ms');
plot(b7(1,:),b7(2,:),'bs');
plot(f7(1,:),f7(2,:),'ms');
plot(b8(1,:),b8(2,:),'bs');
plot(f8(1,:),f8(2,:),'ms');
hold off
t1=0:0.01:1;
B0=(1-t1).^2;
B1=2*(1-t1).*t1;
B2=t1.^2;
B=[B0;B1;B2];
b=[0,1,6;0,2,3];
f=b*B;
t=1/3;
hold on
plot(b(1,:),b(2,:),'r-');
plot(f(1,:),f(2,:),'b');
b1=zeros(2,2);b2=zeros(2,1);
for i=1:2
9
b1(:,i)=b(:,i).*(1-t)+b(:,i+1).*t;
end
b2(:,1)=b1(:,1).*(1-t)+b1(:,2).*t;
plot(b1(1,:),b1(2,:),'-g*')
plot(b2(1,:),b2(2,:),'m*')
hold off
%b)
function exp140(p)
b=exp140subpctA(p);
for k=1:5
plot(p(1,k),p(2,k),'gs')
hold on
end
plot(b(1,:),b(2,:),'bx')
hold on
t=0:.0001:1;
B0=(1-t).^5;
B1=5*(1-t).^4.*(t);
B2=10*(1-t).^3.*t.^2;
10
B3=10*(1-t).^2.*t.^3;
B4=5*(1-t).*t.^4;
B5=t.^5;
B=[B0;B1;B2;B3;B4;B5];
x=b*B; %curba Bezier interpolatoare
comet(x(1,:),x(2,:));
hold off
end
Interpolare F-Mill
%Ex p 142
%a)
function [ b ] = FMill( p )
n=max(size(p));
l=zeros(2,n-2);
[a,e]=ginput(1);
[c,d]=ginput(1);
for j=1:(n-2)
l(:,j)=p(:,j+2)-p(:,j);
end
ultim=3*(n-1)+1;
b=ones(2,ultim);
b(:,1)=p(:,1);
b(:,2)=[a;e];
b(:,3)=p(:,2)-(1/6)*l(:,1);
for k=1:(n-3)
b(:,3*k+1)=p(:,k+1);
b(:,3*k+2)=p(:,k+1)+(1/6)*l(:,k);
b(:,3*k+3)=p(:,k+2)-(1/6)*l(:,k+1);
end
b(:,3*(n-2)+1)=p(:,n-1);
b(:,3*(n-2)+2)=p(:,n-1)+(1/6)*l(:,n-2);
b(:,3*(n-2)+3)=[c,d];
b(:,ultim)=p(:,n);
end
%b)
function reprezintaPoligonFMill( p )
b=FMill(p)
n=max(size(p));
ultim=3*(n-1)+1;
i=1;
11
nr=1;
ng=floor(ultim/4)+1;
t=0:.0001:1;
B0=(1-t).^3;
B1=3*(1-t).^2.*t;
B2=3*(1-t).*t.^2;
B3=t.^3;
B=[B0;B1;B2;B3];
while nr<=ng
plot(b(1,i:i+3),b(2,i:i+3),'kx-');
hold on
cb=b(:,i:i+3)*B;
plot(cb(1,:),cb(2,:));
%comet(cb(1,:),cb(2,:));
nr=nr+1;
i=i+3;
end
end
12
13