Extracting points from a 3D Spline
조회 수: 4 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (1개)
Jayanti
2025년 3월 17일
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” :
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Splines에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!