Docsity

Hermite Curve: Implementation and Visualization in MATLAB - Prof. Kumar, Assignments of Computer Aided Design (CAD)

Partial preview of the text

Download Hermite Curve: Implementation and Visualization in MATLAB - Prof. Kumar and more Assignments Computer Aided Design (CAD) in PDF only on Docsity!

Q

clc; clear all; u = linspace(0, 1, 100); h1 = 2u.^3 - 3u.^2 + 1; h2 = - 2u.^3 + 3u.^2; h3 = u.^3 - 2*u.^2 + u; h4 = u.^3 - u.^2; figure; plot(u, h1, 'r', u, h2, 'b', u, h3, 'g', u, h4, 'k'); title('Blending Functions of Hermite Curve'); legend('h1', 'h2', 'h3', 'h4'); xlabel('u'); ylabel('Blending Function Values'); grid on;

Q

(a) clc; clear all; M=[2 - 2 1 1 ;-3 3 - 2 - 1;0 0 1 0;1 0 0 0]; V=[2 2;5.5 2;0 4;0 - 4]; i=1; for u=[0:0.01:1] U=[u.^3 u.^2 u 1]; P=UMV X(i)=P(1); Y(i)=P(2); i=i+1; hold on; end plot(X,Y); axis equal quiver(V(1,1),V(1,2),V(3,1),V(3,2),0.1,'r'); quiver(V(2,1),V(2,2),V(4,1),V(4,2),0.1,'r'); axis equal title('Hermite Curve'); xlabel('x'); ylabel('y');

Q 2

(c) clc; clear all; i = 1; M = [2 - 2 1 1; - 3 3 - 2 - 1; 0 0 1 0; 1 0 0 0]; V = [0 0; 5 0;-5 5;-1 7]; B = [0 0; 5 0;5 - 5;1 - 7]; for u = [0:0.01:1] U = [u^3 u^2 u 1]; P1 = U * M * V; P2 = U * M * B; X1(i) = P1(1); Y1(i) = P1(2); X2(i) = P2(1); Y2(i) = P2(2); i = i + 1; plot(X1, Y1, X2, Y2); hold on end quiver(V(1,1), V(1,2), V(3,1), V(3,2), 0.1, 'r') quiver(B(2,1), B(2,2), B(4,1), B(4,2), 0.1, 'b') quiver(V(2,1), V(2,2), V(4,1), V(4,2), 0.1, 'k') quiver(B(1,1), B(1,2), B(3,1), B(3,2), 0.1, 'r') axis equal title('Hermite Curve'); xlabel('x'); ylabel('y');

Q 2 (d) clc; clear all; M=[2 - 2 1 1 ;-3 3 - 2 - 1;0 0 1 0;1 0 0 0]; V=[2 2;5.5 2;- 2 - 4;- 2 - 4]; i=1; for u=[0:0.01:1] U=[u.^3 u.^2 u 1]; P=UMV X(i)=P(1); Y(i)=P(2); i=i+1; hold on; end plot(X,Y); axis equal quiver(V(1,1),V(1,2),V(3,1),V(3,2),0.1,'r'); quiver(V(2,1),V(2,2),V(4,1),V(4,2),0.1,'r'); axis equal title('Hermite Curve'); xlabel('x'); ylabel('y');

Q2(f) clc; clear all; M=[2 - 2 1 1 ;-3 3 - 2 - 1;0 0 1 0;1 0 0 0]; V=[2 2;5.5 2;- 2 - 4;- 2 - 4]; i=1; for u=[0:0.01:1] U=[u.^3 u.^2 u 1]; P=UMV X(i)=P(1); Y(i)=P(2); i=i+1; hold on; end plot(X,Y); axis equal quiver(V(1,1),V(1,2),V(3,1),V(3,2),0.1,'r'); quiver(V(2,1),V(2,2),V(4,1),V(4,2),0.1,'r'); axis equal title('Hermite Curve'); xlabel('x'); ylabel('y');

Q2(g) clc; clear all; M=[2 - 2 1 1 ;-3 3 - 2 - 1;0 0 1 0;1 0 0 0]; V=[2 2;5.5 2;12 0;0 - 5]; i=1; for u=[0:0.01:1] U=[u.^3 u.^2 u 1]; P=UMV X(i)=P(1); Y(i)=P(2); i=i+1; hold on; end plot(X,Y); axis equal quiver(V(1,1),V(1,2),V(3,1),V(3,2),0.1,'r'); quiver(V(2,1),V(2,2),V(4,1),V(4,2),0.1,'r'); axis equal title('Hermite Curve'); xlabel('x'); ylabel('y');

Q2(i) clc; clear all; M=[2 - 2 1 1 ;-3 3 - 2 - 1;0 0 1 0;1 0 0 0]; V=[2 2;5.5 2;13 13;0 5]; i=1; for u=[0:0.01:1] U=[u.^3 u.^2 u 1]; P=UMV X(i)=P(1); Y(i)=P(2); i=i+1; hold on; end plot(X,Y); axis equal quiver(V(1,1),V(1,2),V(3,1),V(3,2),0.1,'r'); quiver(V(2,1),V(2,2),V(4,1),V(4,2),0.1,'r'); axis equal title('Hermite Curve'); xlabel('x'); ylabel('y');

Q

clc; clear all; p0 = [0, 0]; p1 = [1, 1]; t0_initial = [1, 0]; t1_initial = [1, 0]; t0_new = [0.5, 0.5]; t1_new = [0.5, - 0.5]; u = linspace(0, 1, 100); H0 = 2u.^3 - 3u.^2 + 1; H1 = - 2u.^3 + 3u.^2; H2 = u.^3 - 2u.^2 + u; H3 = u.^3 - u.^2; x1 = H0p0(1) + H1p1(1) + H2t0_initial(1) + H3t1_initial(1); y1 = H0p0(2) + H1p1(2) + H2t0_initial(2) + H3t1_initial(2); x2 = H0p0(1) + H1p1(1) + H2t0_new(1) + H3t1_new(1); y2 = H0p0(2) + H1p1(2) + H2t0_new(2) + H3*t1_new(2); figure; plot(x1, y1, 'b--', 'LineWidth',0.5); hold on; plot(x2, y2, 'r-', 'LineWidth', 0.5); quiver(p0(1), p0(2), t0_initial(1), t0_initial(2)); quiver(p1(1), p1(2), t1_initial(1), t1_initial(2)); quiver(p0(1), p0(2), t0_new(1), t0_new(2)); quiver(p1(1), p1(2), t1_new(1), t1_new(2)); title('Hermite Curve'); xlabel('x'); ylabel('y'); legend('Original Hermite Curve', 'New Hermite Curve', ... 'Initial Tangent at p0', 'Initial Tangent at p1', ... 'New Tangent at p0', 'New Tangent at p1'); grid on; axis equal; hold off;

Q

clc; clear all; i = 1; M = [2 - 2 1 1; - 3 3 - 2 - 1; 0 0 1 0; 1 0 0 0]; V = [0 0; 5 0;-5 5;-1 7]; B = [0 0; 5 0;5 - 5;1 - 7]; for u = [0:0.01:1] U = [u^3 u^2 u 1]; P1 = U * M * V; P2 = U * M * B; X1(i) = P1(1); Y1(i) = P1(2); X2(i) = P2(1); Y2(i) = P2(2); i = i + 1; plot(X1, Y1, X2, Y2); hold on end quiver(V(1,1), V(1,2), V(3,1), V(3,2), 0.1, 'r') quiver(B(2,1), B(2,2), B(4,1), B(4,2), 0.1, 'b') quiver(V(2,1), V(2,2), V(4,1), V(4,2), 0.1, 'k') quiver(B(1,1), B(1,2), B(3,1), B(3,2), 0.1, 'r') axis equal title('Hermite Curve'); xlabel('x'); ylabel('y');