%This is a script for the homework for 3.6 %3.6.1.a point0 = [0, 0]; point1 = [5, 2]; control0 = [1, 1]; control1 = [6, 1]; t = 0:0.01:1; [x, y, xNums, yNums] = Hermite(point0, point1, control0, control1); %Display the polynomial itself disp('Problem 3.1.a') disp(['x(t) = ' num2str(xNums(1)) 't^3 + ' num2str(xNums(2)) 't^2 + ' num2str(xNums(3)) 't + ' num2str(xNums(4))]) disp(['y(t) = ' num2str(yNums(1)) 't^3 + ' num2str(yNums(2)) 't^2 + ' num2str(yNums(3)) 't + ' num2str(yNums(4))]) figure hold on; %Plot the points plot(control0(1), control0(2), 'o') plot(control1(1), control1(2), 'o') plot(point0(1), point0(2), 'o') plot(point1(1), point1(2), 'o') %Plot the line from the first control point to the first point as a dotted line plot([control0(1), point0(1)], [control0(2), point0(2)], ':') %Plot the line from the last control point to the last point as a dotted line plot([control1(1), point1(1)], [control1(2), point1(2)], ':') %Plot the curve between the two points plot(x(t), y(t)) %3.6.1.b control0 = [0.5, 0.5]; control1 = [5.5, 1.5]; [x, y, xNums, yNums] = Hermite(point0, point1, control0, control1); %Display the polynomial itself disp('') disp('Problem 3.1.b') disp(['x(t) = ' num2str(xNums(1)) 't^3 + ' num2str(xNums(2)) 't^2 + ' num2str(xNums(3)) 't + ' num2str(xNums(4))]) disp(['y(t) = ' num2str(yNums(1)) 't^3 + ' num2str(yNums(2)) 't^2 + ' num2str(yNums(3)) 't + ' num2str(yNums(4))]) figure hold on; %Plot the points plot(control0(1), control0(2), 'o') plot(control1(1), control1(2), 'o') plot(point0(1), point0(2), 'o') plot(point1(1), point1(2), 'o') %Plot the line from the first control point to the first point as a dotted line plot([control0(1), point0(1)], [control0(2), point0(2)], ':') %Plot the line from the last control point to the last point as a dotted line plot([control1(1), point1(1)], [control1(2), point1(2)], ':') %Plot the curve between the two points plot(x(t), y(t)) %3.6.2.a control0 = [1, 1]; control1 = [6, 1]; t = 0:0.01:1; [x, y, xNums, yNums] = Bezier(point0, point1, control0, control1); %Display the polynomial itself disp('') disp('Problem 3.6.2.a') disp(['x(t) = ' num2str(xNums(1)) 't^3 + ' num2str(xNums(2)) 't^2 + ' num2str(xNums(3)) 't + ' num2str(xNums(4))]) disp(['y(t) = ' num2str(yNums(1)) 't^3 + ' num2str(yNums(2)) 't^2 + ' num2str(yNums(3)) 't + ' num2str(yNums(4))]) figure hold on; %Plot the points plot(control0(1), control0(2), 'o') plot(control1(1), control1(2), 'o') plot(point0(1), point0(2), 'o') plot(point1(1), point1(2), 'o') %Plot the line from the first control point to the first point as a dotted line plot([control0(1), point0(1)], [control0(2), point0(2)], ':') %Plot the line from the last control point to the last point as a dotted line plot([control1(1), point1(1)], [control1(2), point1(2)], ':') %Plot the curve between the two points plot(x(t), y(t)) %3.6.2.b control0 = [0.5, 0.5]; control1 = [5.5, 1.5]; [x, y, xNums, yNums] = Bezier(point0, point1, control0, control1); %Display the polynomial itself disp('') disp('Problem 3.6.2.b') disp(['x(t) = ' num2str(xNums(1)) 't^3 + ' num2str(xNums(2)) 't^2 + ' num2str(xNums(3)) 't + ' num2str(xNums(4))]) disp(['y(t) = ' num2str(yNums(1)) 't^3 + ' num2str(yNums(2)) 't^2 + ' num2str(yNums(3)) 't + ' num2str(yNums(4))]) figure hold on; %Plot the points plot(control0(1), control0(2), 'o') plot(control1(1), control1(2), 'o') plot(point0(1), point0(2), 'o') plot(point1(1), point1(2), 'o') %Plot the line from the first control point to the first point as a dotted line plot([control0(1), point0(1)], [control0(2), point0(2)], ':') %Plot the line from the last control point to the last point as a dotted line plot([control1(1), point1(1)], [control1(2), point1(2)], ':') %Plot the curve between the two points plot(x(t), y(t)) clear control0 control1 point0 point1 t x xNums y yNums