Create a node in the space between two nodes (A and B) and following the direction normal to a node (N)
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
Catalytic
2024-2-5
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.
采纳的回答
Matt J
2024-2-5
编辑:Matt J
2024-2-5
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 个评论
Matt J
2024-3-20
编辑:Matt J
2024-3-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)
更多回答(3 个)
Catalytic
2024-2-5
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 个评论
Shubham
2024-2-6
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!