Added functions for homework 3.6

This commit is contained in:
2018-11-06 19:27:36 -05:00
parent 83e17b81a6
commit 4d1b4187ef
3 changed files with 176 additions and 0 deletions

100
Homework/Homework36.m Normal file
View File

@@ -0,0 +1,100 @@
%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