Lab_2
Lab_2
Systemy CAD/CAE
1. function spline2D_comp()
2.
3. knot_vectorx % data;
4. knot_vectory % data;
5.
6. coefficient_vector %data;
7.
8. precision = 0.01
9.
10. %macros
11. compute_nr_basis_functions = @(knot_vector,p) size(knot_vector, 2) -
p - 1
12. mesh = @(a,c) [a:precision*(c-a):c]
13.
14. %splines in x
15. px = compute_p(knot_vectorx)
16. tx = check_sanity(knot_vectorx,px)
17. nrx = compute_nr_basis_functions(knot_vectorx,px)
18.
19. x_begin = knot_vectorx(1)
20. x_end = knot_vectorx(size(knot_vectorx,2))
21.
22. x=mesh(x_begin,x_end);
23.
24. %splines in y
25. py = compute_p(knot_vectorx)
26. ty = check_sanity(knot_vectorx,py)
27. nry = compute_nr_basis_functions(knot_vectorx,py)
28.
29. y_begin = knot_vectory(1)
30. y_end = knot_vectory(size(knot_vectory,2))
31.
32. y=mesh(y_begin,y_end);
33.
34. %X and Y coordinates of points over the 2D mesh
35. [X,Y]=meshgrid(x,y);
36.
37. M = zeros(length(x), length(y));
38.
39. for i=1:nrx
40. %compute values of
41. vx=compute_spline(knot_vectorx,px,i,X);
42. for j=1:nry
43. vy=compute_spline(knot_vectory,py,j,Y);
44. spline = vx .* vy;
45.
46. M = M + spline .* coefficient_vector(i, j)
47. end
48. end
49. surf(X,Y,M);
50.
51. return
knot_vectorx = [0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 16];
knot_vectory = [0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 16];
coefficient_vector = [
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1;
1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1;
1 0 1 1 1 0 1 0 1 1 1 0 1 1 1 0 1;
1 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 1;
1 0 1 0 1 1 1 1 1 0 1 1 1 0 1 0 1;
1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1;
1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1;
1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1;
1 1 1 1 1 0 1 0 1 1 1 0 1 1 1 1 1;
1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1;
1 1 1 0 1 1 1 1 1 0 1 1 1 0 1 1 1;
1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1;
1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1;
1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1;
1 1 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1;
1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1;
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1;
];
3. Wygenerowany labirynt