Asked by Niels
on 14 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!

Opportunities for recent engineering grads.

Apply Today
## 3 Comments

## John D'Errico (view profile)

## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/169931-interpolate-arbitrary-curve-to-regular-x-y-grid#comment_260581

## Niels (view profile)

## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/169931-interpolate-arbitrary-curve-to-regular-x-y-grid#comment_260686

## Niels (view profile)

## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/169931-interpolate-arbitrary-curve-to-regular-x-y-grid#comment_261263

Sign in to comment.