![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1593461/image.png)
Improving the interpolation of nodes arranged in a circle on a plane
1 回表示 (過去 30 日間)
古いコメントを表示
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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1593306/image.png)
Also, is it possible to keep the coordinates of the nodes 'outermost_nodes_sel' fixed?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1593311/image.png)
0 件のコメント
採用された回答
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,
load('outermost_nodes_sel.mat')
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1593461/image.png)
0 件のコメント
その他の回答 (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");
load("outermost_nodes_sel.mat");
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 件のコメント
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);
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!