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

12 views (last 30 days)

Show older comments

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

Catalytic
on 5 Feb 2024

### Accepted Answer

Matt J
on 5 Feb 2024

Edited: Matt J
on 5 Feb 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)

normal_plane'*C %Check that it lies in the plane

dot(A-B,N-C) %Check normality

f=@(z) z(1:3);

norm(cross(f(C-A),f(B-A))) %Check co-linearity of C with [A,B]

##### 13 Comments

Matt J
on 20 Mar 2024

Edited: Matt J
on 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)

### More Answers (3)

Catalytic
on 5 Feb 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

##### 0 Comments

Shubham
on 6 Feb 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:

- Calculate the midpoint (M) between nodes A and B. This gives you a point that lies directly between them.
- Determine the desired distance (d) you want node C to be from the midpoint M along the normal direction.
- Scale the normal vector (normal_plane) to have the desired length (d).
- 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.

##### 0 Comments

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!