Main Content

이 번역 페이지는 최신 내용을 담고 있지 않습니다. 최신 내용을 영문으로 보려면 여기를 클릭하십시오.

2차원 및 3차원에서 스플라인 곡선 생성하기

이 예제에서는 Curve Fitting Toolbox™의 cscvn 명령을 사용하여 2차원 및 3차원에서 3차 스플라인 곡선을 생성하는 방법을 보여줍니다.

점 선택하기

이 예제에서는 점 목록의 점을 나타나는 순서대로 통과하여 매끄러운 곡선을 그리는 방법을 보여줍니다. 먼저 평면에서 임의의 점을 선택하고 행렬에 당 점 하나씩 저장합니다.

npts = 10;
xy = [randn(1,npts); randn(1,npts)];
plot(xy(1,:),xy(2,:),'ro','LineWidth',2);
text(xy(1,:), xy(2,:),[repmat('  ',npts,1), num2str((1:npts)')])
ax = gca;
ax.XTick = [];
ax.YTick = [];

Figure contains an axes object. The axes object contains 11 objects of type line, text. One or more of the lines displays its values using only markers

점 연결하기

다음으로, cscvn 명령을 사용하여 곡선을 생성하고 fnplt를 사용하여 이 곡선을 플로팅합니다.

hold on
fnplt(cscvn(xy),'r',2)
hold off

Figure contains an axes object. The axes object contains 12 objects of type line, text. One or more of the lines displays its values using only markers

점 목록을 대화형 방식으로 입력하려면 getcurve 명령을 사용할 수도 있습니다.

3차원 스플라인 곡선

3차원에서도 마찬가지로 쉽게 스플라인 곡선을 만들 수 있습니다. 이번에는 랜덤 성격이 덜한 작업을 해 보겠습니다. 먼저 점을 생성합니다.

npts = 13;
t = linspace(0,8*pi,npts);
z = linspace(-1,1,npts);
omz = sqrt(1-z.^2);
xyz = [cos(t).*omz; sin(t).*omz; z];
plot3(xyz(1,:),xyz(2,:),xyz(3,:),'ro','LineWidth',2);
text(xyz(1,:),xyz(2,:),xyz(3,:),[repmat('  ',npts,1), num2str((1:npts)')])
ax = gca;
ax.XTick = [];
ax.YTick = [];
ax.ZTick = [];
box on

Figure contains an axes object. The axes object contains 14 objects of type line, text. One or more of the lines displays its values using only markers

점 연결하기

다음은 cscvn이 위의 점을 통과하여 생성한 3차원 스플라인 곡선입니다. 목록의 끝에 첫 번째 점을 추가한 결과 매끄러운 닫힌 곡선을 얻을 수 있었습니다.

hold on
fnplt(cscvn(xyz(:,[1:end 1])),'r',2)
hold off

Figure contains an axes object. The axes object contains 15 objects of type line, text. One or more of the lines displays its values using only markers