multiple 3D plane plotting

Hi I have the following code to plot a 2D plane in 3D space.
the plane is describe by their dip angle and azimuth and the center point is at [x,y] = [0,0]
I intend to modify this code so that it can plot 3 planes in the same axis. However, the location for each plane will be varies depending on the x and y location.
planedip = 30;
planeazim = 120;
% Convert angles to radians
dip_angle_rad = deg2rad(planedip);
dip_azimuth_rad = deg2rad(360 - planeazim); % rotate from CCW to CW
% Define normal vector of plane
normal = [sin(dip_angle_rad)*cos(dip_azimuth_rad), sin(dip_angle_rad)*sin(dip_azimuth_rad), cos(dip_angle_rad)];
% Define two vectors in plane
v1 = [1, 0, (-normal(1)/normal(3))];
v2 = cross(normal, v1);
% Plot plane
x = linspace(-1,1,10);
y = linspace(-1,1,10);
[X,Y] = meshgrid(x,y);
Z = (-normal(1)*X - normal(2)*Y)/normal(3);
surf(X,Y,Z,'FaceColor',[0.5,0.5,0.5],'FaceAlpha',0.5,'EdgeColor','none');
% Add annotations
hold on
quiver3(0, 0, 0, normal(1), normal(2), normal(3));
projection = [normal(1), normal(2), 0];
quiver3(0, 0, 0, projection(1), projection(2), projection(3));
% Add dashed line
plot3([normal(1), projection(1)], [normal(2), projection(2)], [normal(3), projection(3)], '--k');
view(45,30);
axis equal
xlabel('x');
ylabel('y');
zlabel('z');

 采纳的回答

Matt J
Matt J 2024-4-1
编辑:Matt J 2024-4-1
Using this FEX download,
planedip = 30;
planeazim = 120;
% Convert angles to radians
dip_angle_rad = deg2rad(planedip);
dip_azimuth_rad = deg2rad(360 - planeazim); % rotate from CCW to CW
% Define normal vector of plane
normal = [sin(dip_angle_rad)*cos(dip_azimuth_rad), sin(dip_angle_rad)*sin(dip_azimuth_rad), cos(dip_angle_rad)];
ezplane([normal,0],'FaceColor','r'); grid on; hold on
ezplane([normal,+1],'FaceColor','g');
ezplane([normal,-1],'FaceColor','b'); hold off; axis auto; view(35,10)

8 个评论

Hi Matt, thanks.
I want to keep the Z level the same for all plane instead the variation would be on the lateral, i.e. defined by the the x and y location. How can we do this?
Matt J
Matt J 2024-4-1
编辑:Matt J 2024-4-1
I don't really know what that means. What is the "Z-level" of a plane? What is it's "x and y location"?
In any case, if you read the help doc for ezplane, it will tell you how the plane is to be specified in terms of its equation A*x+B*Y*C*z+D=0
in the original code, the center point of the plane is located at [x,y,z] = [0,0,0].
Now that I want to plot them at the new location of [x1,y1,z1] = [2,3,0]
and I also have two more planes having the location of:
[x1,y1,z1] = [5,6,0]
[x1,y1,z1] = [7,8,0]
But the same normal?
BeeTiaw
BeeTiaw 2024-4-1
编辑:BeeTiaw 2024-4-1
Yes. the normal for each plane will be defined by their respective dip angle and azimuth angle.
So, here is the complete dataset I would have:
  1. Plane-1. Dip angle 30deg, dip azimuth 120deg. [x,y,z] = [2,3,0]
  2. Plane-2. Dip angle 60deg, dip azimuth 90deg. [x,y,z] = [6,8,0]
  3. Plane-3. Dip angle 90deg, dip azimuth 270deg. [x,y,z] = [10,15,0]
planedip = [30, 60 90]';
planeazim = [120, 90, 270]';
% Convert angles to radians
dip_angle_rad = deg2rad(planedip);
dip_azimuth_rad = deg2rad(360 - planeazim); % rotate from CCW to CW
% Define normal vector of plane
Normals = [sin(dip_angle_rad).*cos(dip_azimuth_rad),...
sin(dip_angle_rad).*sin(dip_azimuth_rad),...
cos(dip_angle_rad)];
D=[2,3,0;
6,8,0;
10 15 0].*-Normals; D=sum(D,2);
colors=["m","b","g","r"];
for i=1:numel(planedip)
ezplane( [Normals(i,:),D(i)], 'FaceColor',colors(i)); grid on; hold on
end; hold off
axis auto; view(75,25);
xlabel X; ylabel Y; zlabel Z;
Hi, thanks! this is not what I am looking for based on the original code.
In the original code, the location Z is determined from the following lines in the code:
% Plot plane
x = linspace(-1,1,10);
y = linspace(-1,1,10);
[X,Y] = meshgrid(x,y);
Z = (-normal(1)*X - normal(2)*Y)/normal(3);
surf(X,Y,Z,'FaceColor',[0.5,0.5,0.5],'FaceAlpha',0.5,'EdgeColor','none');
whereas now, I want Z to be fix at 0.
Matt J
Matt J 2024-4-1
编辑:Matt J 2024-4-1
You cannot have Z=0 everywhere and also have the plane oriented according to freely chosen planedip and planeazim. Those things contradict each other. If Z=0 everywhere, then the plane normal must be [0,0,1].

请先登录,再进行评论。

更多回答(2 个)

Starting in R2024b, you can use the constantplane function to generate planes based on their vector normals. Using Matt J's demo, here's the constantplane version.
planedip = 30;
planeazim = 120;
% Convert angles to radians
dip_angle_rad = deg2rad(planedip);
dip_azimuth_rad = deg2rad(360 - planeazim); % rotate from CCW to CW
% Define normal vector of plane
normal = [sin(dip_angle_rad)*cos(dip_azimuth_rad), sin(dip_angle_rad)*sin(dip_azimuth_rad), cos(dip_angle_rad)]
normal = 1×3
-0.2500 -0.4330 0.8660
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
constantplane(normal,0,'FaceColor','r'); grid on; hold on
constantplane(normal,+1,'FaceColor','g');
constantplane(normal,-1,'FaceColor','b'); hold off; axis auto; view(35,10)
xlim([-6 6])
ylim([-6 6])
zlim([-6 6])
Catalytic
Catalytic 2024-4-1
编辑:Catalytic 2024-4-1
planedip = [30, 60 90]';
planeazim = [120, 90, 270]';
center=[2,3,0;
6,8,0;
10 15,0];
dip_angle_rad = deg2rad(planedip);
dip_azimuth_rad = deg2rad(360 - planeazim);
% Define normal vector of plane
Normals = [sin(dip_angle_rad).*cos(dip_azimuth_rad),...
sin(dip_angle_rad).*sin(dip_azimuth_rad),...
cos(dip_angle_rad)];
box=[-1 -1; -1 +1; +1 +1; +1 -1];
colors=["m","b","g"];
for i=1:numel(planedip)
P=box*null(Normals(i,:))' + center(i,:);
patch(P(:,1), P(:,2), P(:,3),colors(i));
end; hold off
axis auto; view(-65,40); grid on; axis equal
xlabel X; ylabel Y; zlabel Z;

标签

Community Treasure Hunt

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

Start Hunting!

Translated by