mirror of
https://bitbucket.org/Mattrixwv/octavefunctions.git
synced 2025-12-06 18:53:57 -05:00
Added functions for homework 3.6
This commit is contained in:
38
Bezier.m
Normal file
38
Bezier.m
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
function [x, y, xNums, yNums] = Bezier(point0, point1, control0, control1)
|
||||||
|
%
|
||||||
|
%This function returns a function handle to the hermite polynomial for the points given
|
||||||
|
%[x, y, xNums, yNums] = Hermite(point0, point1, control0, control1)
|
||||||
|
%All of the parameters are [x, y] coordinates
|
||||||
|
%x is a function handle for the polynomial for x. x(t)
|
||||||
|
%y is a function handle for the polynomial for y. y(t)
|
||||||
|
%xNums is an array with the numbers for the x polynomial, starting a t^3 and working down
|
||||||
|
%yNums is an array with the numbers for the y polynomial, starting a t^3 and working down
|
||||||
|
%
|
||||||
|
|
||||||
|
xNums = [0, 0, 0, 0];
|
||||||
|
yNums = [0, 0, 0, 0];
|
||||||
|
a = [(control0(1) - point0(1)), (point1(1) - control1(1))];
|
||||||
|
b = [(control0(2) - point0(2)), (point1(2) - control1(2))];
|
||||||
|
|
||||||
|
%t^3 number
|
||||||
|
xNums(1) = (2 * (point0(1) - point1(1))) + (3 * (a(1) + a(2)));
|
||||||
|
%t^2 number
|
||||||
|
xNums(2) = (3 * (point1(1) - point0(1))) - (3 * (a(2) + (2 * a(1))));
|
||||||
|
%t number
|
||||||
|
xNums(3) = (3 * a(1));
|
||||||
|
%constant
|
||||||
|
xNums(4) = point0(1);
|
||||||
|
%Function handle
|
||||||
|
x = @(t) (xNums(1) * t.^3) + (xNums(2) * t.^2) + (xNums(3) * t) + xNums(4);
|
||||||
|
|
||||||
|
%The t^3 number
|
||||||
|
yNums(1) = (2 * (point0(2) - point1(2))) + (3 * (b(1) + b(2)));
|
||||||
|
%The t^2 number
|
||||||
|
yNums(2) = (3 * (point1(2) - point0(2))) - (3 * (b(2) + (2 * b(1))));
|
||||||
|
%The t number
|
||||||
|
yNums(3) = (3 * b(1));
|
||||||
|
%The constant
|
||||||
|
yNums(4) = point0(2);
|
||||||
|
%Function handle
|
||||||
|
y = @(t) (yNums(1) * t.^3) + (yNums(2) * t.^2) + (yNums(3) * t) + yNums(4);
|
||||||
|
end
|
||||||
38
Hermite.m
Normal file
38
Hermite.m
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
function [x, y, xNums, yNums] = Hermite(point0, point1, control0, control1)
|
||||||
|
%
|
||||||
|
%This function returns a function handle to the hermite polynomial for the points given
|
||||||
|
%[x, y, xNums, yNums] = Hermite(point0, point1, control0, control1)
|
||||||
|
%All of the parameters are [x, y] coordinates
|
||||||
|
%x is a function handle for the polynomial for x. x(t)
|
||||||
|
%y is a function handle for the polynomial for y. y(t)
|
||||||
|
%xNums is an array with the numbers for the x polynomial, starting a t^3 and working down
|
||||||
|
%yNums is an array with the numbers for the y polynomial, starting a t^3 and working down
|
||||||
|
%
|
||||||
|
|
||||||
|
xNums = [0, 0, 0, 0];
|
||||||
|
yNums = [0, 0, 0, 0];
|
||||||
|
a = [(control0(1) - point0(1)), (point1(1) - control1(1))];
|
||||||
|
b = [(control0(2) - point0(2)), (point1(2) - control1(2))];
|
||||||
|
|
||||||
|
%t^3 number
|
||||||
|
xNums(1) = (2 * (point0(1) - point1(1))) + (a(1) + a(2));
|
||||||
|
%t^2 number
|
||||||
|
xNums(2) = (3 * (point1(1) - point0(1))) - (a(2) + (2 * a(1)));
|
||||||
|
%t number
|
||||||
|
xNums(3) = (a(1));
|
||||||
|
%constant
|
||||||
|
xNums(4) = point0(1);
|
||||||
|
%Function handle
|
||||||
|
x = @(t) (xNums(1) * t.^3) + (xNums(2) * t.^2) + (xNums(3) * t) + xNums(4);
|
||||||
|
|
||||||
|
%The t^3 number
|
||||||
|
yNums(1) = (2 * (point0(2) - point1(2))) + (b(1) + b(2));
|
||||||
|
%The t^2 number
|
||||||
|
yNums(2) = (3 * (point1(2) - point0(2))) - (b(2) + (2 * b(1)));
|
||||||
|
%The t number
|
||||||
|
yNums(3) = (b(1));
|
||||||
|
%The constant
|
||||||
|
yNums(4) = point0(2);
|
||||||
|
%Function handle
|
||||||
|
y = @(t) (yNums(1) * t.^3) + (yNums(2) * t.^2) + (yNums(3) * t) + yNums(4);
|
||||||
|
end
|
||||||
100
Homework/Homework36.m
Normal file
100
Homework/Homework36.m
Normal 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
|
||||||
Reference in New Issue
Block a user