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

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 Comments

Yes there is a way D=(A+B)/2; % the location E=cross((A-B),(N-D)); % the direction
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.

Sign in to comment.

 Accepted Answer

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 Comments

Hi @Matt J! Regarding your answer, I would like to ask you why, using the attached data, node 'C' is on the line of nodes 'A' and 'B' but is not passing through the yellow plane. I would like node 'C' to be located as in the figure (see node 'Cc'). Can you help me?
%%
A = importdata("A_test.mat");
B = importdata("B_test.mat");
N = importdata("G_test.mat");
nodes_test = importdata("nodes_test.mat");
%%
A = [A, 1]';
B = [B, 1]';
N = [N, 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 = C';
C = C(1,1:3);
A = A';
A = A(1,1:3);
B = B';
B = B(1,1:3);
% =================
figure
plot3(N(1),N(2),N(3),'r.','Markersize',20)
hold on
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
plot3(A(:,1),A(:,2),A(:,3),'c.','Markersize',20)
plot3(B(:,1),B(:,2),B(:,3),'m.','Markersize',20)
plot3(C(:,1),C(:,2),C(:,3),'g.','Markersize',20)
hold off
axis equal
grid off
node 'C' is on the line of nodes 'A' and 'B' but is not passing through the yellow plane
It is not clear what defines the "yellow plane". It doesn't even look like a plane, but rather 3 colinear yellow dots. In your original post, the requirements on the plane were that it be normal to [A,B] and contain the point N. You can see below that that is still true with this new set of data.
%%
A = importdata("A_test.mat");
B = importdata("B_test.mat");
N = importdata("G_test.mat");
%%
A = [A, 1]';
B = [B, 1]';
N = [N, 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);
% =================
figure
plot3(N(1),N(2),N(3),'r.','Markersize',20)
xlabel x; ylabel y; zlabel z; axis equal
hold on
plot3(A(1),A(2),A(3),'c.','Markersize',20)
plot3(B(1),B(2),B(3),'m.','Markersize',20)
plot3(C(1),C(2),C(3),'g.','Markersize',20)
D=N+2*(C-N);
plot3(D(1),D(2),D(3),'.','MarkerFaceColor','none');
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)
Sorry Matt, yellow plan (not plane ahaha). Yellow plan passing through 3 yellow nodes.
The 'problem' is that the green node C I also want it on the plane and not just between nodes A and B!
So the requirement that the plane be perpendicular to [A,B] is gone (or was never there)? And if the plane is determined entirely by the 3 nodes_test data points, what is the purpose of the additional given point N?
The condition that point C must lie between A and B is valid.
Node N may indeed be ignored (it lies on the yellow plan).
In that case, there isn't much that needs changing. Just use planarFit(), which you are familiar with, to fit a plane to the nodes_test data,
P=planarFit(nodes_test);
normal_plane=[P.normal, -P.d];
and the rest of the code should work as before.
Could you tell me where to use these lines of code within the code you provided?
I had replaced these two lines of code with yours but not work
n = B-A; %normal
normal_plane = [n(1:3);-n'*N]; %plane
%%
A = importdata("A_test.mat");
B = importdata("B_test.mat");
%%
A = [A, 1]';
B = [B, 1]';
P=planarFit(nodes_test);
n=P.normal;
normal_plane=[P.normal, -P.d];
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)
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)
Probably because normal_plane is a row vector and should be a column vector.
I changed the vector to an column vector but I do not get the desired result.
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)
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)

Sign in to comment.

More Answers (3)

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
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.

Categories

Products

Release

R2021b

Asked:

on 5 Feb 2024

Edited:

on 20 Mar 2024

Community Treasure Hunt

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

Start Hunting!