# Improving the interpolation of nodes arranged in a circle on a plane

조회 수: 6 (최근 30일)
Alberto Acri 2024년 1월 17일
댓글: Mathieu NOE 2024년 1월 18일
I am using this code to improve the interpolation of nodes arranged in a circle on a plane.
As input I have the nodes 'outermost_nodes_sel'.
outermost_nodes_sel = importdata("outermost_nodes_sel.txt");
figure
plot3(outermost_nodes_sel(:,1), outermost_nodes_sel(:,2), outermost_nodes_sel(:,3), 'r.', 'Markersize', 15);
hold off
axis equal
xlabel('x')
ylabel('y')
zlabel('z')
% Interpolation
Nt = size(outermost_nodes_sel,1);
t = 1:Nt;
t_new = linspace(1,Nt,3*Nt-1);
line_new = interp1(t,outermost_nodes_sel,t_new);
figure
plot3(line_new(:,1), line_new(:,2), line_new(:,3), 'r.', 'Markersize', 15);
hold off
axis equal
xlabel('x')
ylabel('y')
zlabel('z')
It generates this space for me. How do I insert nodes there too?
Also, is it possible to keep the coordinates of the nodes 'outermost_nodes_sel' fixed?

댓글을 달려면 로그인하십시오.

### 채택된 답변

Matt J 2024년 1월 17일
편집: Matt J 2024년 1월 17일
You could fit a circle to the given points and then resample it using this FEX download,
P=planarFit(outermost_nodes_sel');
xy0=P.project2D(outermost_nodes_sel'); %Map measured 3D samples to 2D
c=circularFit(xy0); %Perform circular fit in 2D
XYZ=P.unproject3D( cell2mat(c.sample(0:5:360)) ); %Post-sample the ellipse fit and map back to 3D
%%Visualize
hold on
scatter3(outermost_nodes_sel(:,1) , outermost_nodes_sel(:,2), outermost_nodes_sel(:,3),...
'b','filled','SizeData',100);
scatter3(XYZ(1,:), XYZ(2,:), XYZ(3,:),'r','filled');
grid on
view(3)
legend Original Interpolated
hold off

댓글을 달려면 로그인하십시오.

### 추가 답변 (1개)

Mathieu NOE 2024년 1월 17일
hello Alberto
try this - I think it's easier once you work in polar coordinates.
I am not sure to understand by "is it possible to keep the coordinates of the nodes 'outermost_nodes_sel' fixed?" ?
you can overlay both sets of data - this will do nothing to the values of outermost_nodes_sel array
% outermost_nodes_sel = importdata("outermost_nodes_sel.txt");
figure
plot3(outermost_nodes_sel(:,1), outermost_nodes_sel(:,2), outermost_nodes_sel(:,3), 'r.', 'Markersize', 15);
hold off
axis equal
xlabel('x')
ylabel('y')
zlabel('z')
[TH,R,Z] = cart2pol(outermost_nodes_sel(:,1), outermost_nodes_sel(:,2), outermost_nodes_sel(:,3));
% Interpolation
Nt = size(outermost_nodes_sel,1);
t = 1:Nt;
TH_new = linspace(min(TH),min(TH)+2*pi,3*Nt-1); % make sure the range is 2*pi
line_new = interp1(TH,[R Z],TH_new);
[x,y,z] = pol2cart(TH_new, line_new(:,1), line_new(:,2));
figure
plot3(x, y, z, 'r.', 'Markersize', 15);
hold off
axis equal
xlabel('x')
ylabel('y')
zlabel('z')
##### 댓글 수: 2없음 표시없음 숨기기
Alberto Acri 2024년 1월 17일
Thank you for your answer! How can I create a rowsx3 matrix of those nodes you see with this line of code?
plot3(x, y, z, 'r.', 'Markersize', 15);
I would like to reproduce it like this:
plot3(node_interp(:,1), node_interp(:,2), node_interp(:,3), 'r.', 'Markersize', 15);
Thanks!
Mathieu NOE 2024년 1월 18일
hello again
node_interp = [x(:) y(:) z(:)];
plot3(node_interp(:,1), node_interp(:,2), node_interp(:,3), 'r.', 'Markersize', 15);

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by