Find coordinates inside a matrix with specific conditions
5 ビュー (過去 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!