Interpolate arbitrary curve to regular (x,y) grid

19 views (last 30 days)
Niels on 14 Jan 2015
Commented: Niels on 19 Jan 2015
Hello,
I ran into a problem that I cannot seem to solve in an elegant way.
Say, I have a spiral-like curve which I want to map onto a regular grid (constant dx and dy values). The curve is described by a large amount of points which I want to reduce to a much smaller amount of (roughly equidistant) points.
Since many points share the same x- or y-values, however, I cannot use e.g. John D'Errico's interparc tool.
Currently, my approach is as follows:
• Calculate the length of each line segment
• Generate an equidistant line with the desired number of points and a total length equal to my spiral-like curve
• Use dsearchn with my original curve and the equidistant line as inputs to determine which indices of the original curve to keep
• Use dsearchn again with my (x,y) grid and the remaining curve from the previous step as inputs to find the grid points that are closest to the remaining curve
However, this approach has 2 problems:
• dsearchn does not take into account uniqueness of points: some of curve points map onto the same grid point. This is something I want to avoid.
• The shape of the original curve is only roughly preserved (fair enough), but some points are pretty much inbetween 2 grid points (nearly the same distance) and the other point would preserve the original shape much better.
I am aware that mapping a pretty smooth curve to a relatively coarse Cartesian grid may give problems, but especially the first problem is one I really want to solve and I'm pretty sure there must be a way.
Does anyone have an idea?
Thanks!

John D'Errico on 14 Jan 2015
If multiple points share an x or y value, but not both, you can still use interparc. It is only replicate points that will cause it to fail.
If you do have true n-dimensional replicates, then first remove the replicates with unique, or with my consolidator, found on the file exchange. Consolidator can also look for replicates with a tolerance, averaging them down into a single point each.
So you can still use interparc. It does not do what you ask to do in terms of quantizing the curve though, but I'm not really sure I understand what your goal is there.
Niels on 15 Jan 2015
Hi John,
Using interparc I get the following error:
Error using chckxy (line 51)
The data sites should be distinct.
Error in spline (line 54)
[x,y,sizey,endslopes] = chckxy(x,y);
Error in interparc (line 316)
spl{i} = spline(cumarc,pxy(:,i));
A quick google search tells me that this error is caused due to non-distinct x or y values (unless I misunderstood). The curve segments itself are not particularly equidistant (the closer towards the center, the denser the points get in order to preserve the shape well - see the attached picture) and my goal is to maybe avoid my main problem by obtaining coordinates for points that were not in my original curve.
The real problem still is, however, the fact that dsearchn interpolates different points from my curve to the same grid coordinates.
Niels on 19 Jan 2015
Up to now I have not been able to find a good solution for my problem.
To sum up all the above; is there a way to extract a (small) number of equidistant points from a spiral-like curve (with varying line segment sizes) and subsequently distribute these points over a regular 2D grid where each of the points is assigned to a unique grid point?