Find coordinates inside a matrix with specific conditions

2 次查看(过去 30 天)
I need to identify 3 nodes (the green ones, but it can also be the blue ones) within a matrix that generates a "circle" in space.
The figure is just an example, the important thing is that one node (A) is above the centre node, node (B) is below, node (C) is to the left.
Any good ideas?
plane_new = importdata("plane_new_ok.mat");
node_new = importdata("node_new_ok.mat");
figure
plot3(plane_new(:,1), plane_new(:,2), plane_new(:,3), 'r.', 'Markersize', 15);
hold on
plot3(node_new(:,1), node_new(:,2), node_new(:,3), 'r.', 'Markersize', 15);
hold off
axis equal
xlabel('x')
ylabel('y')
zlabel('z')
  2 个评论
Matt J
Matt J 2024-1-17
Are A,B,C to be selected from points actually present in plane_new_ok.mat, even if there is no subset of points that are at perfect 90 degree intervals?
Alberto Acri
Alberto Acri 2024-1-17
Hi Matt! The nodes to be searched must be in 'plane_new_ok.mat'. Starting from any node in 'plane_new_ok.mat' (node A), I must find the other two nodes (B and C) arranged at approximately (or ugual) 90°!

请先登录,再进行评论。

采纳的回答

Matt J
Matt J 2024-1-17
编辑:Matt J 2024-1-17
Using this FEX download,
plane_new = importdata("plane_new_ok.mat");
node_new = importdata("node_new_ok.mat");
[~,i]=max(plane_new(:,3)); %arbitrarioy choose A
A=plane_new(i,:);
rA=A-node_new; %A-axis
P=planarFit([plane_new;node_new]');
rn=P.normal*sign(P.normal(3)); %plane normal
rC=cross(rn,rA); %C-axis
C=nearestPoint(node_new,+rC,plane_new);
B=nearestPoint(node_new,-rA,plane_new);
figure
plot3(plane_new(:,1), plane_new(:,2), plane_new(:,3), 'r.', 'Markersize', 15);
hold on
plot3(node_new(:,1), node_new(:,2), node_new(:,3), 'r.', 'Markersize', 15);
plot3(A(1), A(2),A(3), 'b.', 'Markersize', 40);
plot3(C(1), C(2),C(3), 'g.', 'Markersize', 40);
plot3(B(1), B(2),B(3), 'k.', 'Markersize', 40);
hold off
axis equal
xlabel('x')
ylabel('y')
zlabel('z')
legend('Data','Center','A','B','C')
function G=nearestPoint(c,d,xyz)
d=d/norm(d);
s=(xyz-c)*d'>0;
xyz=xyz(s,:);
Dist=vecnorm(cross(xyz-c,repmat(d,height(xyz),1)),2,2);
[~,ipos]=min(Dist);
G=xyz(ipos,:);
end

更多回答(0 个)

类别

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