# Interpolation using B-spline or Nurbs

7 visualizaciones (últimos 30 días)
mukesh bisht el 31 de Jul. de 2021
Respondida: Vinayak el 23 de Mayo de 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
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (1)

Vinayak el 23 de Mayo de 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.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Interpolation en Help Center y File Exchange.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by