Intepolate in 2D loop of points

12 views (last 30 days)
awinka
awinka on 10 Mar 2016
Commented: Robert on 28 Mar 2016
Hi all,
I have a shape made up of regularly spaced data points in 2D. I want to increase the sampling of the points, i.e. interpolate between points as I need the outer edge in higher resolution than it is currently. I have tried intep etc, alphaShape and meshgrid but am struggling, so any help would be great. I have also tried just doing it for the points that make up the perimeter of the shape as this is what I'm interested in, but didn't get anywhere with that easier and thought it might be easier to do it as a whole object?
An example of a data set can be seen below.
%-2.57812500000000 -2.92968750000000
-2.57812500000000 -3.04687500000000
-2.57812500000000 -3.16406250000000
-2.57812500000000 -3.28125000000000
-2.57812500000000 -3.39843750000000
-2.57812500000000 -3.51562500000000
-2.57812500000000 -3.63281250000000
-2.57812500000000 -3.75000000000000
-2.57812500000000 -3.86718750000000
-2.57812500000000 -3.98437500000000
-2.46093750000000 -2.81250000000000
-2.46093750000000 -2.92968750000000
-2.46093750000000 -3.04687500000000
-2.46093750000000 -3.16406250000000
-2.46093750000000 -3.28125000000000
-2.46093750000000 -3.39843750000000
-2.46093750000000 -3.51562500000000
-2.46093750000000 -3.63281250000000
-2.46093750000000 -3.75000000000000
-2.46093750000000 -3.86718750000000
-2.46093750000000 -3.98437500000000
-2.34375000000000 -2.57812500000000
-2.34375000000000 -2.69531250000000
-2.34375000000000 -2.81250000000000
-2.34375000000000 -2.92968750000000
-2.34375000000000 -3.04687500000000
-2.34375000000000 -3.16406250000000
-2.34375000000000 -3.28125000000000
-2.34375000000000 -3.39843750000000
-2.34375000000000 -3.51562500000000
-2.34375000000000 -3.63281250000000
-2.34375000000000 -3.75000000000000
-2.34375000000000 -3.86718750000000
-2.22656250000000 -2.46093750000000
-2.22656250000000 -2.57812500000000
-2.22656250000000 -2.69531250000000
-2.22656250000000 -2.81250000000000
-2.22656250000000 -2.92968750000000
-2.22656250000000 -3.04687500000000
-2.22656250000000 -3.16406250000000
-2.22656250000000 -3.28125000000000
-2.22656250000000 -3.39843750000000
-2.22656250000000 -3.51562500000000
-2.22656250000000 -3.63281250000000
-2.22656250000000 -3.75000000000000
-2.22656250000000 -3.86718750000000
-2.10937500000000 -2.46093750000000
-2.10937500000000 -2.57812500000000
-2.10937500000000 -2.69531250000000
-2.10937500000000 -2.81250000000000
-2.10937500000000 -2.92968750000000
-2.10937500000000 -3.04687500000000
-2.10937500000000 -3.16406250000000
-2.10937500000000 -3.28125000000000
-2.10937500000000 -3.39843750000000
-2.10937500000000 -3.51562500000000
-2.10937500000000 -3.63281250000000
-2.10937500000000 -3.75000000000000
-2.10937500000000 -3.86718750000000
-1.99218750000000 -2.34375000000000
-1.99218750000000 -2.46093750000000
-1.99218750000000 -2.57812500000000
-1.99218750000000 -2.69531250000000
-1.99218750000000 -2.81250000000000
-1.99218750000000 -2.92968750000000
-1.99218750000000 -3.04687500000000
-1.99218750000000 -3.16406250000000
-1.99218750000000 -3.28125000000000
-1.99218750000000 -3.39843750000000
-1.99218750000000 -3.51562500000000
-1.99218750000000 -3.63281250000000
-1.99218750000000 -3.75000000000000
-1.87500000000000 -2.34375000000000
-1.87500000000000 -2.46093750000000
-1.87500000000000 -2.57812500000000
-1.87500000000000 -2.69531250000000
-1.87500000000000 -2.81250000000000
-1.87500000000000 -2.92968750000000
-1.87500000000000 -3.04687500000000
-1.87500000000000 -3.16406250000000
-1.87500000000000 -3.28125000000000
-1.87500000000000 -3.39843750000000
-1.87500000000000 -3.51562500000000
-1.87500000000000 -3.63281250000000
-1.87500000000000 -3.75000000000000
-1.75781250000000 -2.34375000000000
-1.75781250000000 -2.46093750000000
-1.75781250000000 -2.57812500000000
-1.75781250000000 -2.69531250000000
-1.75781250000000 -2.81250000000000
-1.75781250000000 -2.92968750000000
-1.75781250000000 -3.04687500000000
-1.75781250000000 -3.16406250000000
-1.75781250000000 -3.28125000000000
-1.75781250000000 -3.39843750000000
-1.75781250000000 -3.51562500000000
-1.75781250000000 -3.63281250000000
-1.75781250000000 -3.75000000000000
-1.64062500000000 -2.46093750000000
-1.64062500000000 -2.57812500000000
-1.64062500000000 -2.69531250000000
-1.64062500000000 -2.81250000000000
-1.64062500000000 -2.92968750000000
-1.64062500000000 -3.04687500000000
-1.64062500000000 -3.16406250000000
-1.64062500000000 -3.28125000000000
-1.64062500000000 -3.39843750000000
-1.64062500000000 -3.51562500000000
-1.64062500000000 -3.63281250000000
-1.64062500000000 -3.75000000000000
-1.52343750000000 -2.46093750000000
-1.52343750000000 -2.57812500000000
-1.52343750000000 -2.69531250000000
-1.52343750000000 -2.81250000000000
-1.52343750000000 -2.92968750000000
-1.52343750000000 -3.04687500000000
-1.52343750000000 -3.16406250000000
-1.52343750000000 -3.28125000000000
-1.52343750000000 -3.39843750000000
-1.52343750000000 -3.51562500000000
-1.52343750000000 -3.63281250000000
-1.40625000000000 -2.46093750000000
-1.40625000000000 -2.57812500000000
-1.40625000000000 -2.69531250000000
-1.40625000000000 -2.81250000000000
-1.40625000000000 -2.92968750000000
-1.40625000000000 -3.04687500000000
-1.40625000000000 -3.16406250000000
-1.40625000000000 -3.28125000000000
-1.40625000000000 -3.39843750000000
-1.40625000000000 -3.51562500000000
-1.40625000000000 -3.63281250000000
-1.28906250000000 -2.57812500000000
-1.28906250000000 -2.69531250000000
-1.28906250000000 -2.81250000000000
-1.28906250000000 -2.92968750000000
-1.28906250000000 -3.04687500000000
-1.28906250000000 -3.16406250000000
-1.28906250000000 -3.28125000000000
-1.28906250000000 -3.39843750000000
-1.28906250000000 -3.51562500000000
-1.28906250000000 -3.63281250000000
-1.17187500000000 -2.69531250000000
-1.17187500000000 -2.81250000000000
-1.17187500000000 -2.92968750000000
-1.17187500000000 -3.04687500000000
-1.17187500000000 -3.16406250000000
-1.17187500000000 -3.28125000000000
-1.17187500000000 -3.39843750000000
-1.17187500000000 -3.51562500000000
-1.17187500000000 -3.63281250000000
-1.05468750000000 -2.81250000000000
-1.05468750000000 -2.92968750000000
-1.05468750000000 -3.04687500000000
-1.05468750000000 -3.16406250000000
-1.05468750000000 -3.28125000000000
-1.05468750000000 -3.39843750000000
-1.05468750000000 -3.51562500000000
-1.05468750000000 -3.63281250000000
-0.937500000000000 -2.92968750000000
-0.937500000000000 -3.04687500000000
-0.937500000000000 -3.16406250000000
-0.937500000000000 -3.28125000000000
-0.937500000000000 -3.39843750000000
-0.937500000000000 -3.51562500000000
-0.937500000000000 -3.63281250000000
-0.820312500000000 -3.04687500000000
-0.820312500000000 -3.16406250000000
-0.820312500000000 -3.28125000000000
-0.820312500000000 -3.39843750000000
-0.820312500000000 -3.51562500000000
-0.820312500000000 -3.63281250000000
-0.703125000000000 -3.28125000000000
-0.703125000000000 -3.39843750000000
-0.703125000000000 -3.51562500000000
-0.703125000000000 -3.63281250000000
end

Accepted Answer

Robert
Robert on 10 Mar 2016
If I were you, I would throw away the data that is not on the edges by finding the min and max of each of your columns of data points. This takes advantage of the even spacing in your example dataset. If you don't have that nice spacing in your real data you could bin the values in x to achieve the same result.
Once you have two curves describing the top and bottom edges you can do whatever interpolation or smoothing you like. The code below will demonstrate a few options available to you.
% your example data is stored in the variable x (a 176x2 double array)
clf
plot(x(:,1),x(:,2),'.')
x0 = unique(x(:,1)); % get one value for each "column" of data
for ii = length(x0):-1:1 % for each column of data
these = x(:,1)==x0(ii); % find the corresponding indices
y0_lo(ii) = min(x(these,2)); % get the min y value (second column of x)
y0_hi(ii) = max(x(these,2)); % get the max y value
end
hold all
plot(x0,y0_lo,x0,y0_hi)
% interpolate to 100 points
x1 = linspace(min(x0),max(x0),100);
y1_lo = interp1(x0,y0_lo,x1,'spline');
y1_hi = interp1(x0,y0_hi,x1,'pchip');
plot(x1,y1_lo,x1,y1_hi)
% moving average with width 3 (from the Curve Fitting Toolbox)
y2_lo = smooth(y0_lo,3);
y2_hi = smooth(y0_hi,3);
plot(x0,y2_lo,x0,y2_hi)
hold off
  3 Comments
awinka
awinka on 22 Mar 2016
Hi Robert, having initially thought this did what I needed, I actually need the entire loops to be interpolated - this does the top and bottom points, but I also need the side points if you understand. I have uploaded a picture with the points which are just along the top to try and help.
Any further advice would be much appreciated. Lou
Robert
Robert on 28 Mar 2016
In your example dataset your sides are just straight lines. With no other constraints, I would suggest you simply take those min/max x values as your sides.
What you decide to do will depend on what your data means and what you intend to do with it, so I don't have enough information to guess what option would be best for you.
I can suggest that if you want a more round shape you could use polar coordinates. Take the mean of your values as the origin and convert the data to polar coordinates. Then bin your data by angle, take the max distance in each bin, and interpolate over those values. (Duplicate the first value or few values on the end of the list to make the result smooth at your loop's start/end.)

Sign in to comment.

More Answers (0)

Categories

Find more on Interpolation 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!