0% found this document useful (0 votes)
164 views13 pages

Proiect Geometrie Computationala PDF

This document discusses vector operations and representations in MATLAB such as addition, scalar multiplication, dot and cross products, symmetries, and projections. It also covers curve representation using Bernstein polynomials, Bezier curves, and the de Casteljau algorithm for evaluating Bezier curves. Functions are provided to plot vectors and curves, perform operations, and interpolate points with Bezier curves.

Uploaded by

Angela Biro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
164 views13 pages

Proiect Geometrie Computationala PDF

This document discusses vector operations and representations in MATLAB such as addition, scalar multiplication, dot and cross products, symmetries, and projections. It also covers curve representation using Bernstein polynomials, Bezier curves, and the de Casteljau algorithm for evaluating Bezier curves. Functions are provided to plot vectors and curves, perform operations, and interpolate points with Bezier curves.

Uploaded by

Angela Biro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Geometrie computationala

(Proiect)

Idu Stefan Andrei


Informatica
Anul I

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

% --- Executes on button press in pushbutton1.


function pushbutton1_Callback(hObject, eventdata, handles)
a=[4 5];
b=[1 10];
c=[2 -8];
d=[-5 10];

v1=[a(1) b(1); a(2) b(2)];


v2=[c(1) d(1); c(2) d(2)];
sum=v1+v2;

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)'

% --- Executes on button press in pushbutton2.


function pushbutton2_Callback(hObject, eventdata, handles)

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

function axes2_CreateFcn(hObject, eventdata, handles)


a=[2 3];
b=[5 9];
c=[1 -7];
d=[-4 3];
hold on
quiver(a(1), b(1), a(2), b(2),0);
quiver(c(1), d(1), c(2), d(2),0);
grid on
axis off
hold off

% --- Executes on button press in pushbutton3.


function pushbutton3_Callback(hObject, eventdata, handles)
v1=[ 1 2 3; 4 3 2];
v2=[ 1 0 0; 4 5 2];
prodVectorial=cross(v1,v2);

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

% --- Executes on button press in pushbutton4.


Function pushbutton4_Callback(hObject, eventdata, handles)
v1=[ 1 2 3; 4 3 2];
v2=[ 1 0 0; 4 5 2];
prod=dot(v1,v2);
<is a=[0 0 0; prod(1) prod(2) prod(3)];

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

% --- Executes on button press in pushbutton5.


Function pushbutton5_Callback(hObject, eventdata, handles)
v1=[ 1 2 ; 4 3];

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

% --- Executes on button press in pushbutton6.


Function pushbutton6_Callback(hObject, eventdata, handles)
v1=[4 3];
r=[0 1];

sim= -v1 -2*dot(-v1,r)*r;

axes(handles.axes2);
legend(handles.axes2,’hide’)
cla
hold on
quiver(0,0,v1(1), v1(2),0,’g’’Linewidth’,2);

plot(r(1), r(2), ‘r’,2);


quiver(0,0,sim(1), sim(2),0,’b’’Linewidth’,2);
legend(‘vector v1’,’punctul r’,’vectorul simetric fata de r’)

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

%Ex 8 p 117 subpunctul a


%Sa se reprezinte grafic curba reprezentata de ecuatia implicita:
%x^2/3+y^2/3=a^2/3, x,y apartin intervalului [-a,a]

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

%Ex.2 p 126 (gr=4)


%Reprezentati in aceeasi figura, in subgrafice diferite, pe 4 linii si
%4 coloane baza Bernstein si baza monomiala

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

Algoritmul lui Casteljau

%Ex. 3 p 138 (n=4)


%Determinarea coordonatelor punctelor de pe o curba Bezier de grad n,
prin
%algoritmul lui de Casteljau si pentru reprezentarea grafica a
algoritmului
%descompunerii CB initiale in subcurba Bezier stanga si dreapta.

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

Interpolare Bezier simpla

%Ex. p140 (n=5, alt p)


%a) Se considera cunoscute coordonatele a 4 puncte in plan. Sa se scrie
% o functie care calculeaza coordonatele poligonului de control ale
curbei
%Bezier care trece prin aceste puncte, considerand ca punctele sunt
%repartizate echidistant pe curba Bezier (corespunzator parametrului t
% al curbei). Coordonatelep unctelor se dau intr-o matrice cu 2 linii si
4
%coloane, coloana dupa coloana.
%b) Sa se reprezinte grafic curba Bezier interpolatoare

* %a)-nu merge spune ca ,,p’’ nu e definit


function [b]=exp140subpctA(p)
A=(1/27)*[27 0 0 0 ; 8 12 6 1 ; 1 6 12 8;0 0 0 27];
b=A.^(-1)*p';
b=b';
end

%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')

p=[2 4 6 -7; 0 8 5 3];


b=exp140subpctA(p);
exp140(p);

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

You might also like