Find coordinates inside a matrix with specific conditions

5 views (last 30 days)
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 Comments
Matt J
Matt J on 17 Jan 2024
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 on 17 Jan 2024
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°!

Sign in to comment.

Accepted Answer

Matt J
Matt J on 17 Jan 2024
Edited: Matt J on 17 Jan 2024
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

More Answers (0)

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!