Interpolation using B-spline or Nurbs

4 views (last 30 days)
mukesh bisht
mukesh bisht on 31 Jul 2021
Answered: Vinayak on 23 May 2024
Hi
I have three data sets inside a circle of radius 3m (Fig & data attached). I want to obtain the following two results
  1. To make closed curve for each data set using spline or Nurbs.
  2. To interplotate a number of such curves i.e. let say 10 such closed curve btw red & purple data set and 10 curve btw purple & green data set.
Please suggest how to do this interpolation using spline or nurbs

Answers (1)

Vinayak
Vinayak on 23 May 2024
Hi Mukesh,
The provided data can be used to create three sets of points: green, purple, and red.
I ensured that the points form a closed shape, typically by setting the final value as the first value:
function points = ensure_closed(points)
if points(:,1) ~= points(:,end)
points(:,end+1) = points(:,1);
end
end
Next, we need to determine the shape of the curve using splines. Here, I used a specific number of points(adjust for smoothness) to be generated along the expected spline:
function splinePoints = interpolateShape(shape, numPoints)
t = linspace(1, length(shape), length(shape));
tt = linspace(1, length(shape), numPoints);
xx = spline(t, shape(1,:), tt);
yy = spline(t, shape(2,:), tt);
splinePoints = [xx; yy];
end
Once you have the splines for all three sets, we can interpolate between each pair to get the interpolated curves between them:
function interpolateBetweenShapes(shape1, shape2, numInterpolations)
colors = jet(numInterpolations); % Colormap for interpolated shapes
for i = 1:numInterpolations
alpha = i / (numInterpolations + 1);
interpolatedShape = (1-alpha) * shape1 + alpha * shape2;
plot(interpolatedShape(1,:), interpolatedShape(2,:), '-', 'Color', colors(i,:), 'LineWidth', 1.5);
end
end
I plotted the result for the green and purple points, and this results in:
Similarly, we can generate the data between the other set of points.

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!