How to Use Interp function to get cartesian coordinates from arc lenth?

11 visualizaciones (últimos 30 días)
Hello,
For my simulations, I read in an array which has x and y coordinates and then I convert it to the streamwise coordinate S ( or arc length) which is basically the distance between adjacent points.
The sample code is below which gets me S. What I would like to do now, is how can I get back x and y from S? I believe I can use the interp1 function but I am not sure what information I need to provide to the function. Any advice or guidance would be greatly appreciated.
%-----------------------------------------------------
x=data(:,1)%get x data
y=data(:,2)%get y data
%now lets get the difference in distance between adjacent points
dx=diff(x)
dy=diff(y)
%now if we have an arc with a delta x and delta y, the length of the arc is
%simply pythagorean theorem
ds=sqrt(dx.^2+dy.^2)
%the length of S will be one less than the lenth of x so we add zero at the
%beginning
s=[0.0;cumsum(ds)]
  9 comentarios
John BG
John BG el 11 de Ag. de 2017
Editada: John BG el 11 de Ag. de 2017
ok,
let be just 3 points:
p1=[1 1]
p2=[2 2]
p3=[3 3]
Dream Chaser only gives you ds
[1.41 1.41]
or s
[0 1.41 2.42]
how on heaven can any one retrieve, not any of p1 p2 p3, but just a single point of the hidden set if not playing mine craft along circles?
But where do you start? there is no common reference!
Dream Chaser would like to know, and I would like to know as well. how can any interpolation, or interpac, or any other other function, solely reading s or ds, come anywhere close to a reasonable guess?
I will mark your answer as accepted, in case Dream Chaser doesn't, if you, Mr John D'Errico, write MATLAB code solving these 3 points, a simplification of Dream Chaser question.
Appreciating time and attention
John BG
John D'Errico
John D'Errico el 13 de Ag. de 2017
John, again, you are focusing on the wrong thing. Focus is good. But here to listen and learn is better.

Iniciar sesión para comentar.

Respuestas (2)

John D'Errico
John D'Errico el 10 de Ag. de 2017
Editada: John D'Errico el 10 de Ag. de 2017
Walter is correct, in that interparc is a viable choice, because it does all the work for you in terms of computing the splines, and then predicting points along the curve. You don't need it though.
It seems you are looking to understand how one can interpolate a parametric function. It looks like you understand the computation of a chordal arclength perfectly. The only trick that remains is to then fit both x(s) and y(s) as splines.
xs = spline(s,x);
ys = spline(s,y);
You can now recover any point along the curve by use of those two splines. For example, the original points are predicted using two calls to ppval (or fnval if you prefer):
xpred = ppval(xs,s);
ypred = ppval(ys,s);
This will predict the original points (to within possible floating point slop, so possible errors on the order of eps.)
Alternatively, you can use interp1.
xpred = interp1(s,x,s);
ypred = interp1(s,y,s);
Any of the interp1 methods will suffice here. Intermediate points along the curve can be computed, by providing intermediate values in terms of arc length.
A nice thing is this general approach allows you to use splines to predict a function along a path in any number of dimensions. In fact, the approach using splines as I show can indeed predict points that wrap around in a circle very nicely. Or, it can handle a curve that crosses itself in a figure 8. Don't forget that splines can be somewhat dangerous though. They do strange things if you push them too far. Sometimes pchip can be a better choice than spline. Knowing when that might be true is important.
Note that you still cannot predict a value y for some given intermediate value of x. At least this will be more difficult, although not always impossible.
  6 comentarios
dream chaser
dream chaser el 16 de Ag. de 2017
John thanks so much for the help! This answered my question and I solved my problem. I'm not sure how to mark your response as accepted? thanks again for your help!
John D'Errico
John D'Errico el 16 de Ag. de 2017
That is always nice to hear. Isn't there an accept this answer button? Hmm. Oh well, I'm not that worried. :) I'm happy that you found it useful, and that is what really matters to me. The goal of Answers is not to get points by answering questions, but to answer questions that need to be answered. So have a nice day.

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 10 de Ag. de 2017
You should instead use interparc() from the File Exchange.

Categorías

Más información sobre Spline Postprocessing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by