Tugas 5 Grafikom

TUGAS 5 GRAFIKA KOMPUTER
(Untuk memenuhi Tugas Mata Ajar Grafika Komputer Semester Genap Tahun Pelajaran 2014/2015)

Nama
NIMq

Disusun oleh
: Ahmad Arif Faizin
: 21060112120027

JURUSAN TEKNIK ELEKTRO
FAKULTAS TEKNIK
UNIVERSITAS DIPONEGORO
2015

1. Spline Interpolation of Sine Data
1.
2.
3.
4.
5.


x = 0:10;
y = sin(x);
xx = 0:.25:10;
yy = spline(x,y,xx);
plot(x,y,'o',xx,yy)

2. Spline Interpolation of Distribution and Specify Endpoint Slopes
1.
2.
3.
4.
5.

x = -4:4;
y = [0 .15 1.12 2.36 2.36 1.46 .49 .06 0];
cs = spline(x,[0 y 0]);
xx = linspace(-4,4,101);
plot(x,y,'o',xx,ppval(cs,xx),'-');


3. Spline Interpolation of Angular Data
1.
2.
3.
4.
5.
6.

x = pi*[0:.5:2];
y = [0 1 0 -1 0 1 0;
1 0 1 0 -1 0 1];
pp = spline(x,y);
yy = ppval(pp, linspace(0,2*pi,101));
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.
2.
3.
4.

5.

x = 0:.25:1;
Y = [sin(x); cos(x)];
xx = 0:.1:1;
YY = spline(x,Y,xx);
plot(x,Y(1,:),'o',xx,YY(1,:),'-')

6. hold on
7. plot(x,Y(2,:),'o',xx,YY(2,:),':')
8. hold off

5. Interpolation
1.
2.
3.
4.
5.
6.
7.

8.

x = 2*pi*[0 1 .1:.2:.9];
y = cos(x);
cs = csapi(x,y);
fnplt(cs,2);
axis([-1 7 -1.2 1.2])
hold on
plot(x,y,'o')
hold off

6. Linear interpolation
1.
2.
3.
4.

x = 2*pi*[0 1 .1:.2:.9];
y = cos(x);
csp = csape( x, y, 'periodic' );

hold on

5. fnplt(csp,'g')
6. hold off
7. cs = csapi(x,y);
8. pl = spapi(2, x, y);
9. hold on
10.
fnplt(pl, 'r', 2)
11.
hold off

7. Knot Selection
1.
2.
3.
4.
5.
6.
7.

8.

x = linspace(0,10,101);
y = exp(x);
sp0 = spap2( augknt(0:2:10,4), 4, x, y );
plot(x,y-fnval(sp0,x),'r','LineWidth',2)
sp1 = spap2( newknt(sp0), 4, x, y );
hold on
plot(x,y-fnval(sp1,x),'k','LineWidth',2)
hold off

9. Hermite Spline
1. x = -3:3;

2.
3.
4.
5.
6.
7.


y = [-1 -1 -1 0 1 1 1];
t = -3:.01:3;
p = pchip(x,y,t);
s = spline(x,y,t);
plot(x,y,'o',t,p,'-',t,s,'-.')
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.
2.
3.
4.
5.

6.
7.

pt1
pt2
pt3
pt4

=
=
=
=

[ 5;-10];
[18; 18];
[38; -5];
[45; 15];

cla
placelabel(pt1,'pt_1');


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) + kron(3*(1-t).^2.*t,pt2) + kron(3*(1t).*t.^2,pt3) + kron(t.^3,pt4);
14.
15. hold on
16. plot(pts(1,:),pts(2,:))
17. hold off