Extracting points from a 3D Spline

4 visualizaciones (últimos 30 días)
Ehtisham Tanvir
Ehtisham Tanvir el 22 de Mayo de 2015
Respondida: Jayanti el 17 de Mzo. de 2025
Hello I have plotted a 3D spline by the following code:
x=[sx pathx endx];
y=[sy pathy endy];
z=[sz pathz endz];
xyz = [x;y; z];
plot3(xyz(1,:),xyz(2,:),xyz(3,:),'ro','LineWidth',2);
%text(xyz(1,:),xyz(2,:),xyz(3,:),[repmat(' ',npts,1), num2str((1:npts)')])
%set(gca,'XTick',[],'YTick',[],'ZTick',[])
box on
hold on
%fnplt(cscvn(xyz(:,[1:end 1])),'r',2)
fnplt(cscvn(xyz(:,:)),'r',2)
hold off
Now I am trying to get all the points on this spline in arrays as I have to use them later on. How can this be done?

Respuestas (1)

Jayanti
Jayanti el 17 de Mzo. de 2025
Hi Ehtisham,
To obtain a set of points along the spline, you can sample it at a finite number of locations. By generating a vector of parameter values you can evaluate the spline at these specific points.
Please refer to the below code for better understanding:
curve = cscvn(xyz(:,:));
t = linspace(curve.breaks(1), curve.breaks(end), 50);
points = fnval(curve, t);
% Extract x, y, z coordinates
x = points (1, :);
y = points (2, :);
z = points (3, :);
“linspace” is a MATLAB function that generates a linearly spaced vector. Above will creates 50 evenly spaced values between the first and last breakpoints of the spline. These values can be used to evaluate the spline.fnval” evaluates the spline at each of these parameter values.
You may refer to the below MathWorks documentation to know more on “linspace” and “fnval” :

Categorías

Más información sobre Splines 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