How to draw a Plane perpendicular to a line and then generate multiple planes at regular intervals

If I have a line defined by
P1 = [1, -1, 3];
P2 = [2, 3, 4];
How can I draw a plane perpendicular to this line please. I have read the previous posts on this but I m not clear how to draw the surface. Plane can be initially at the mid point of the line.
Then I want to be able to generate multiple planes at regular intervals .
Thanks

 Accepted Answer

Hi, I understand that you are trying to generate a plane perpendicular to the line joining those two points. In 3d geometry any plane is defined by the equation ax + by + cz = d , where [a b c] is the direction of plane's normal ( which is perpendicular to the plane )
Hence, direction of normal is P2 - P1. [a b c]
And the dot product of normal and the mid point gives d.
surf helps us plot the planar surface and plot3 to plot 3-d line.
Here is the code
P1 = [1, -1, 3];
P2 = [2, 3, 4];
midpoint = (P1 + P2) / 2;
normal = P2 - P1;
% Create a grid of points for the plane
[X, Y] = meshgrid(-10:10, -10:10);
Z = (-normal(1) * X - normal(2) * Y + dot(normal, midpoint)) / normal(3);
% Plot the plane
figure;
hold on;
surf(X, Y, Z,'FaceAlpha', 0.5);
plot3([P1(1), P2(1)], [P1(2), P2(2)], [P1(3), P2(3)], 'r', 'LineWidth', 2);
hold off;
xlabel('X');
ylabel('Y');
zlabel('Z');
title('Plane Perpendicular to Line Joining Two Points');
grid on;
axis equal;
Refer the documentation for better understanding
Hope it helps.

4 Comments

Thanks very much, That is what I was looking for. Based on that I was able to define multiple oter planes along the line, and working on defining intersection points of several other lines with the plane.
Thank you very much!
Hi @Arya Chandan Reddy Sorry to reach out again, I was able to do my next step from this. But the the moment I change P1 and P2 values I get an error. Only change I ve done is replaced the numbers of Z equation with elements of P1 and P2. It works fine if I keep P1 and P2 same numbers, even If I change one gives me an error.
Index exceeds the number of array elements. Index must not exceed 3. Thanks
P1 = [1, -1, 3];
P2 = [2, 3, 4];
normal = P2 - P1;
midpoint = (P2+P1)/2;
[X, Y] = meshgrid(-10:10, -10:10);
Z = (-normal(P1(1,1)) * X - normal(P2(1,1)) * Y + dot(normal, midpoint)) / normal(P2(1,2));
hold on;
surf(X, Y, Z,'FaceAlpha', 0.1, 'FaceColor',"yellow");
plot3([P1(1), P2(1)], [P1(2), P2(2)], [P1(3), P2(3)], 'r', 'LineWidth', 2);
hold off;
xlabel('X');
ylabel('Y');
zlabel('Z');
title('Plane Perpendicular to Line Joining Two Points');
grid on;
axis equal;
Why are you using the elements of P1 and P2 as indices for normal array while defining Z?
Thanks, yes I get the point. I ve modified it, works fine

Sign in to comment.

More Answers (0)

Categories

Asked:

on 29 Jun 2023

Edited:

on 4 Jul 2023

Community Treasure Hunt

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

Start Hunting!