Find coordinates inside a matrix with specific conditions
4 次查看(过去 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
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?
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!