TUGAS 5 GRAFIKA KOMPUTER
(Untuk memenuhi Tugas Mata Ajar Grafika Komputer Semester Genap Tahun Pelajaran 2014/2015)
Disusun oleh
Nama
: Ahmad Arif Faizin
NIMq
: 21060112120027
JURUSAN TEKNIK ELEKTRO
FAKULTAS TEKNIK
1.
Spline Interpolation of Sine Data
1. x = 0:10; 2. y = sin(x); 3. xx = 0:.25:10;
4. yy = spline(x,y,xx); 5. plot(x,y,'o',xx,yy)
2.
Spline Interpolation of Distribution and Specify Endpoint Slopes
1. x = -4:4;
2. y = [0 .15 1.12 2.36 2.36 1.46 .49 .06 0]; 3. cs = spline(x,[0 y 0]);
4. xx = linspace(-4,4,101);
3.
Spline Interpolation of Angular Data
1. x = pi*[0:.5:2];
2. y = [0 1 0 -1 0 1 0; 3. 1 0 1 0 -1 0 1]; 4. pp = spline(x,y);
5. yy = ppval(pp, linspace(0,2*pi,101));
6. plot(yy(1,:),yy(2,:),'-b',y(1,2:5),y(2,2:5),'or'), axis equal
4.
Spline Interpolation of Sine and Cosine Data
1.
x = 0:.25:1;2.
Y = [sin(x); cos(x)];3.
xx = 0:.1:1;4.
YY = spline(x,Y,xx);6.
hold on7.
plot(x,Y(2,:),'o',xx,YY(2,:),':')8.
hold off5. Interpolation
1.
x = 2*pi*[0 1 .1:.2:.9];2.
y = cos(x);3.
cs = csapi(x,y);4.
fnplt(cs,2);5.
axis([-1 7 -1.2 1.2])6.
hold on7.
plot(x,y,'o')8.
hold off6. Linear interpolation
1.
x = 2*pi*[0 1 .1:.2:.9];2.
y = cos(x);5.
fnplt(csp,'g')6.
hold off7.
cs = csapi(x,y);8.
pl = spapi(2, x, y);9.
hold on10.
fnplt(pl, 'r', 2)11.
hold off7. Knot Selection
1.
x = linspace(0,10,101);2.
y = exp(x);3.
sp0 = spap2( augknt(0:2:10,4), 4, x, y );4.
plot(x,y-fnval(sp0,x),'r','LineWidth',2)5.
sp1 = spap2( newknt(sp0), 4, x, y );6.
hold on7.
plot(x,y-fnval(sp1,x),'k','LineWidth',2)8.
hold off9.
Hermite Spline
2.
y = [-1 -1 -1 0 1 1 1];3.
t = -3:.01:3;4.
p = pchip(x,y,t);5.
s = spline(x,y,t);6.
plot(x,y,'o',t,p,'-',t,s,'-.')7.
legend('data','pchip','spline',4)10.
Cubic Spline Interpolation
1.
x = [1 1.5 2 4.1 5];2.
y = [1 -1 1 -1 1];3.
plot(xx,csapi(x,y,xx),'k-',x,y,'ro')4.
title('Cubic Spline Interpolant to Five Points')11. Beizer Spline
1. pt1 = [ 5;-10]; 2. pt2 = [18; 18]; 3. pt3 = [38; -5]; 4. pt4 = [45; 15]; 5.
6. cla
8. placelabel(pt2,'pt_2'); 9. placelabel(pt3,'pt_3'); 10. placelabel(pt4,'pt_4'); 11. xlim([0 50])
12. axis equal
13. pts = kron((1-t).^3,pt1) + t).^2.*t,pt2) + kron(3*(1-t).*t.^2,pt3) + kron(t.^3,pt4);
14.
15. hold on