MATLAB Answers

Hello everyone, I would like to ask a question how to parameterize data points?

51 views (last 30 days)
Wesley
Wesley on 18 Jan 2021
Edited: Rik on 21 Jan 2021
This question was flagged by Image Analyst
The method of parameterization of data points is as follows:

Answers (1)

Image Analyst
Image Analyst on 18 Jan 2021
Wow, what a load of mathematical gobbledygook. Could they make it any more obtuse? Anyway, here is a start:
s = load('data1.mat')
x = s.data1(:, 1);
y = s.data1(:, 2);
N = length(y);
plot(x, y, 'b.', 'LineWidth', 2);
grid on;
xlabel('x', 'FontSize', 20);
ylabel('y', 'FontSize', 20);
t = zeros(1, N);
denominator = abs(diff(x) .^ 2 + diff(y) .^ 2)
for k = 2 : N - 1
numerator =
t(k) = t(k - 1) + numerator / denominator;
end
t(end) = 1;

  3 Comments

Wesley
Wesley on 18 Jan 2021
Thank you very much, you did a great job. Do you have any better suggestions for this problem? I sincerely ask you for advice.
Image Analyst
Image Analyst on 18 Jan 2021
Sorry, no. I think all you have to do is to fill out numerator. I left that for you because it sounds like a homework problem. And I have little idea what this thing is about. You probably know far, far more about this than me and would be in a better position to solve it.
John D'Errico
John D'Errico on 18 Jan 2021
The idea is to compute what I like to call a connect-the-dots arc length. I've also called it a cumulative chordal relative distance. That is, you connect each point with a straight line, thus a chord. The parameter t is the cumulative accumulation of those distances between pairs of points.
The parameter t is a monotonically increasing parameter as you move from one point to the next in the sequence. And this makes it a nice scheme to do interpolation, because it can be used for any set of points, regardless of how they traverse your domain. For example, you can use it to interpolate points around the perimeter of a circle. And you can also use it to interpolate a completely general curvilinear path through any space, in any number of dimensions.
In MATLAB, this scheme is used internally by cscvn. You can see the reference to Eugene Lee's centripetal scheme in the help thereof.
help cscvn
CSCVN `Natural' or periodic interpolating cubic spline curve. CS = CSCVN(POINTS) returns a parametric `natural' cubic spline that interpolates to the given points POINTS(:,i) at parameter values t(i) , i=1,2,..., with t(i) chosen by Eugene Lee's centripetal scheme, i.e., as accumulated square root of chord-length. When first and last point coincide and there are no double points, then a parametric *periodic* cubic spline is constructed instead. However, double points result in corners. For example, fnplt(cscvn( [1 0 -1 0 1;0 1 0 -1 0] )) shows a (circular) curve through the four vertices of the standard diamond (because of the periodic boundary conditions enforced), while fnplt(cscvn( [1 0 -1 -1 0 1;0 1 0 0 -1 0] )) shows a corner at the double point as well as at the curve endpoint. See also CSAPI, CSAPE, GETCURVE, SPCRVDEM, SPLINE. Documentation for cscvn doc cscvn
I use the same scheme in my tools interparc, arclength, and distance2curve.
Since you have shown how to compute it already, I could add that one can compute the parametric vector t in a vectorized form, using diff and cumsum, but the looped form is a simple way to do it. (I know of course that Image Analyst knows how to do that.) But one might do:
t = cumsum(sqrt(diff(x(:)).^2 + diff(y(:).^2));
t = [0;t/t(end)];
Now a typical interpolation would involve forming spline models x(t), y(t). Sometimes pchip models may be appropriate instead. For example, a similar question was asked recently, where the OP desired to not have the curve falling outside of the box of the points. pchip models for x(t), y(t) would be a good way to achieve that result.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!