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!