Create a node in the space between two nodes (A and B) and following the direction normal to a node (N)

5 vues (au cours des 30 derniers jours)
Hi. I need to create a node in the space between two nodes (A and B) and following the direction normal to a node (N) as in the figure.
Is there a function that can do this? The result are the coordinates of node C.
A = [-25.5530 -185.3199 -211.6502];
B = [-25.4769 -185.6468 -211.2523];
N = [-25.4602 -185.4676 -211.6694];
normal_plane = [0.2437 -0.62123 0.7447];
figure
plot3(N(:,1),N(:,2),N(:,3),'r.','Markersize',25);
hold on
plot3(A(:,1),A(:,2),A(:,3),'k.','Markersize',25);
plot3(B(:,1),B(:,2),B(:,3),'k.','Markersize',25);
hold off
axis equal
grid off
  3 commentaires
Catalytic
Catalytic le 5 Fév 2024
You've asked a million questions on coordinate goemetry on this forum. Surely you now by now how to find the equation of a plane and its intersection with a line.

Connectez-vous pour commenter.

Réponse acceptée

Matt J
Matt J le 5 Fév 2024
Modifié(e) : Matt J le 5 Fév 2024
I might be misinterpreting your question somehow, but from your figure illustration, it doesn't make sense that you would be supplying both N and normal_plane independently. The normal plane there will be a function of A,B, and N.
A = [-25.5530 -185.3199 -211.6502 ,1]'; %work in homogeneous coordinates
B = [-25.4769 -185.6468 -211.2523 ,1]';
N = [-25.4602 -185.4676 -211.6694 ,1]';
n=B-A; %normal
normal_plane=[n(1:3);-n'*N]; %plane
L=(A*B'- B*A'); %The line [A,B]
C=L*normal_plane; C=C/C(4)
C = 4×1
-25.5396 -185.3775 -211.5802 1.0000
normal_plane'*C %Check that it lies in the plane
ans = -1.4211e-14
dot(A-B,N-C) %Check normality
ans = -1.5446e-14
f=@(z) z(1:3);
norm(cross(f(C-A),f(B-A))) %Check co-linearity of C with [A,B]
ans = 4.9595e-12
  13 commentaires
Alberto Acri
Alberto Acri le 20 Mar 2024
Modifié(e) : Alberto Acri le 20 Mar 2024
With this code I obtained this result. The green node C is in an incorrect position. How come?
A = importdata("A_test.mat");
B = importdata("B_test.mat");
N = importdata("G_test.mat");
nodes_test = importdata("nodes_test.mat");
%% DATA
A = [A, 1]';
B = [B, 1]';
P = planarFit(nodes_test);
n = P.normal;
normal_plane = [P.normal, -P.d];
normal_plane = normal_plane';
L = (A*B'- B*A'); %The line [A,B]
C = L*normal_plane;
C = C/C(4);
% =================
figure
plot3(A(1),A(2),A(3),'c.','Markersize',20)
xlabel x; ylabel y; zlabel z; axis equal
hold on
plot3(B(1),B(2),B(3),'m.','Markersize',20)
plot3(C(1),C(2),C(3),'g.','Markersize',20)
plot3(nodes_test(:,1), nodes_test(:,2), nodes_test(:,3), 'y.', 'Markersize', 30);
patch(nodes_test(:,1), nodes_test(:,2), nodes_test(:,3), 'y'); % Plotting the plane
ax=axis;
fsurf(@(x,y) -n(3)\(n(1)*x+n(2)*y + normal_plane(4)),...
'FaceColor','b','FaceAlpha',0.3,'EdgeColor','none');
axis(ax);
grid off
hold off; view(85,20)
Matt J
Matt J le 20 Mar 2024
Modifié(e) : Matt J le 20 Mar 2024
A = importdata("A_test.mat");
B = importdata("B_test.mat");
nodes_test = importdata("nodes_test.mat");
%% DATA
A = [A, 1]';
B = [B, 1]';
P = planarFit(nodes_test'); %<--------------- Note transpose
n = P.normal;
normal_plane = [P.normal, -P.d];
normal_plane = normal_plane';
L = (A*B'- B*A'); %The line [A,B]
C = L*normal_plane;
C = C/C(4);
% =================
figure
plot3(A(1),A(2),A(3),'c.','Markersize',20)
xlabel x; ylabel y; zlabel z; axis equal
hold on
plot3(B(1),B(2),B(3),'m.','Markersize',20)
plot3(C(1),C(2),C(3),'g.','Markersize',20)
plot3(nodes_test(:,1), nodes_test(:,2), nodes_test(:,3), 'y.', 'Markersize', 30);
patch(nodes_test(:,1), nodes_test(:,2), nodes_test(:,3), 'y'); % Plotting the plane
ax=axis;
fsurf(@(x,y) -n(3)\(n(1)*x+n(2)*y + normal_plane(4)),...
'FaceColor','b','FaceAlpha',0.3,'EdgeColor','none');
axis(ax);
grid off
hold off; view(85,20)

Connectez-vous pour commenter.

Plus de réponses (3)

William Rose
William Rose le 5 Fév 2024
D=(A+B)/2; % the location
E=cross((A-B),(N-D)); % the direction
good luck

Catalytic
Catalytic le 5 Fév 2024
A = [-25.5530 -185.3199 -211.6502];
B = [-25.4769 -185.6468 -211.2523];
N = [-25.4602 -185.4676 -211.6694];
C=(B-A)'\(N-A)'*(B-A)+A
C = 1×3
-25.5396 -185.3775 -211.5802

Shubham
Shubham le 6 Fév 2024
Hi Alberto,
To create a node C in the space between two nodes A and B, following the direction normal to a node N, you can follow these steps:
  1. Calculate the midpoint (M) between nodes A and B. This gives you a point that lies directly between them.
  2. Determine the desired distance (d) you want node C to be from the midpoint M along the normal direction.
  3. Scale the normal vector (normal_plane) to have the desired length (d).
  4. Add the scaled normal vector to the midpoint M to find the coordinates of node C.
Here is how you can implement this in MATLAB:
A = [-25.5530, -185.3199, -211.6502];
B = [-25.4769, -185.6468, -211.2523];
N = [-25.4602, -185.4676, -211.6694];
normal_plane = [0.2437, -0.62123, 0.7447];
% Calculate the midpoint between A and B
M = (A + B) / 2;
% Determine the desired distance d for node C from the midpoint M
% This value is for illustration; you'll need to choose an appropriate value.
d = 10; % Replace with the desired distance
% Normalize the normal vector
normal_plane_unit = normal_plane / norm(normal_plane);
% Scale the normal vector to have the desired length d
normal_plane_scaled = normal_plane_unit * d;
% Calculate the coordinates of node C
C = M + normal_plane_scaled;
% Plotting
figure
plot3(N(1), N(2), N(3), 'r.', 'Markersize', 25); hold on;
plot3(A(1), A(2), A(3), 'k.', 'Markersize', 25);
plot3(B(1), B(2), B(3), 'k.', 'Markersize', 25);
plot3(C(1), C(2), C(3), 'b.', 'Markersize', 25); % Node C in blue
hold off;
axis equal;
grid on;
In the code above, d is a placeholder for the distance you want node C to be from the midpoint M along the normal direction. You'll need to define d based on your specific requirements. The normal vector is also scaled to this distance and then added to the midpoint M to find the coordinates of node C.
Node C is plotted in blue for distinction. Make sure to adjust the value of d as needed for your specific use case. If you want node C to be placed in a different way related to node N, you would need to adjust the calculation accordingly.

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by