Interpolate arbitrary curve to regular (x,y) grid
Show older comments
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!
3 Comments
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 19 Jan 2015
Answers (0)
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!