- #1
arian487
- 5
- 0
Basically, I'm supposed to write my name using splines in Matlab. Now, I'm having some trouble getting a parametric spline to work and I can't for the life of me figure out the problem. I'm making use of the spline toolbox and I have written a script as so:
The parametric spline does the following:
When I run this, I get a parametric curve but it doesn't go through all of the points. For some reason it leaves a few out. However, if I don't run a linspace on tt it DOES go through all the points but it isn't a curve, just straight lines connecting the points. Any ideas on what I'm doing wrong?
Code:
%segment for the S
x1 = [0 2 1 2 3];
y1 = [1 0 2.5 1 3];
[x_t y_t t] = ParametricSpline(x1, y1);
xref = ppval (x_t, t);
yref = ppval(y_t, t);
plot(x1, y1, 'o', xref, yref);
The parametric spline does the following:
Code:
function [ x_t, y_t, tt ] = ParametricSpline(x , y)
%ParametricSpline Summary of this function goes here
% Detailed explanation goes here
arc_length = 0;
n = length(x);
t = zeros(n, 1);
for i=2:n
arc_length = sqrt((x(i)-x(i-1))^2 + (y(i)-y(i-1))^2);
t(i) = t(i-1) + arc_length;
end
x_t = spline(t, x);
y_t = spline(t, y);
tt = linspace(1,n,1000);
end
When I run this, I get a parametric curve but it doesn't go through all of the points. For some reason it leaves a few out. However, if I don't run a linspace on tt it DOES go through all the points but it isn't a curve, just straight lines connecting the points. Any ideas on what I'm doing wrong?