extract points from spline

6 vues (au cours des 30 derniers jours)
deep
deep le 22 Jan 2019
Commenté : deep le 25 Jan 2019
Dear All,
I have a problem in hand.
I have developed a spline from given set of points using 'interparc.m' suggested by john D'errico. I have been successful in creating the splines.
Now the spline is created using say (y,z) points now if i have to extract x for a given z location how can i do that.
This (y,z) is a set of ship section and i need the x location for each given z at all the y locations.
Can this be done?
And How can it be done?

Réponse acceptée

John D'Errico
John D'Errico le 22 Jan 2019
Modifié(e) : John D'Errico le 22 Jan 2019
Ok, so you are drawing hull sections. For each z, I gather what you mean by this is you have a curve for each value of z, so some implicit function as pairs of (x,y). In your last question, z was not a factor. So I can only assume that you are trying to loft a hull from these sections.
Now, you wish to interpolate this relationship. Here is the hull section you posted from your last question.
plot(x,y,'o')
xlabel X
ylabel Y
grid on
Note that in that file you posted, we had z and x as identical vectors. But I can only read what you have said here, and try to infer what you are doing and what you really want t odo. (At least I got you out of the idea of trying to use a polynomial model to interpolate those points.)
A problem you will face in trying to interpolate these sections is there is a bit of noise in your data. As well, you have an infinite slope in this, down near x=y=1. So the third point was apparently misread, as 1.0078. My guess is it was really 1.078, not 1.0078.
[x,y]
ans =
1 1
1.01 2.13
1.0078 3.261
1.1205 4.385
1.3478 5.492
2.182 7.586
2.817 8.52
3.58 9.353
4.429 10.099
6.265 11.42
7.225 12.01
8.203 12.58
9.188 13.13
10.18 13.68
12.19 14.72
14.24 15.66
16.36 16.44
18.56 16.95
20.82 17.1
Anyway, now you are asking how to interpolate that curve, trying to gain x as a function of y, for a fixed value of z? Or is your hull section actually allowing x, y, and z to vary all in one curve?
A simple way to solve the problem, based on this data, as long as the y data is monotonic (as it is here) is to use pchip. We can just interpolate at any y. So, actually, interp1 can be used, or you can use pchip, and then ppval.
yev = linspace(min(y,max(y),500);
xev = interp1(y,x,yev,'pchip');
Or do this:
yev = linspace(min(y,max(y),500);
spl = pchip(y,x);
xev = ppval(spl,yev);
Note that I carefully used y and x in that order as I called pchip, or interp1. The above will work as long as the curve at the top end is still single valued, so we have a nice functional relationship x(y). So, here we swap axes, to get the curve drawn as
plot(y,x,'o')
xlabel Y
ylabel X
grid on
untitled.jpg
So the curveas drawn here does not have an infinite slope at the ight end. And even the wiggle caused by the inaccurate third value of y will cause no problem. If you have some other desired set of points yev, then create them as you desire. So, hereif we want x at y==10, the result is as simple as:
spl = pchip(y,x);
ppval(spl,10)
ans =
4.3074
So you can create a nice well-behaved curve, thus a list of values xev, at some fixed set of values yev.
Note that I was careful to suggest the use of pchip here, as the spline utility can cause problems if the curves get more wonky than you have shown. True splines can generate ringing-like oscillations.
As well, while I originally suggested in your last question that you could use interparc to draw the curve, you don't actually need it for this specific problem. You can get away with simply pchip, something which is already in MATLAB. One problem when you ask a question where we don't really know where you are going and what you really need to do, is it can be hard to give the best advice. In order to do that, we really need to understand your end goal.
My only fear based on your question here is that now your lofted curve actually varies in x, y, and z, all three variables moving together. If that is true, then you need to explain that to be the case. (And give me some data I can use for an example to teach you how to work with it.)
  1 commentaire
deep
deep le 25 Jan 2019
Hi,
Delayed response due to my unwell health.
My only fear based on your question here is that now your lofted curve actually varies in x, y, and z, all three variables moving together.
This isnt the case.
My problem for now is resolved.
Thank you.

Connectez-vous pour commenter.

Plus de réponses (1)

KSSV
KSSV le 22 Jan 2019
Read about interp1 or knnsearch....Also you can do the absolute difference between the points and get the indices of the value you want.
  1 commentaire
John D'Errico
John D'Errico le 22 Jan 2019
Modifié(e) : John D'Errico le 22 Jan 2019
Based on the last question, the points do not form a functional relationship. In fact, not only is there an infinite slope, but noise/slop in the points apparently makes the relationship non-single valued. So some care must be taken.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Geometric Transformation and Image Registration dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by