3D volume plot

4 views (last 30 days)
Anshul Jain
Anshul Jain on 24 Dec 2022
Answered: Jaswanth on 16 Oct 2024
Respected sir,
I have two entities A and B with their respective 200 (x,y,z) coordinates. (Plz see attached excel sheet).
Entity A is bigger than entity B in volume.
I already have a 3D volume plot of B inside A as an isometric view with respective X, Y and Z axes (Transparent plot using syntax "alpha(0.25)'')
But I want Top-view(shown in the X,Y axes) of the same in the same plot of isometric view (means isometric view and top view in the same plot).
Kindly help me in this regard.
I have used one code for the same as given below but it is not working properly for the Top view. For isometric view it is working fine.
T1 = readtable('Book1.xlsx', 'Sheet',1, 'Range','G1:I201');
T1 = table2array(T1);
T2 = readtable('ForPlot.xlsx', 'Sheet',1, 'Range','L1:N201');
T2 = table2array(T2);
x1=T1(:,1);
y1=T1(:,2);
z1=T1(:,3);
x2=T2(:,1);
y2=T2(:,2);
z2=T2(:,3);
kkk=boundary(x1,y1,z1);
V1=trisurf(kkk,x1,y1,z1,'Facecolor','r','Edgecolor','none');
hold on
kkk=boundary(x2,y2,z2);
V2=trisurf(kkk,x2,y2,z2,'Facecolor','y','Edgecolor','none');
alpha(0.25);
legend([V1 V2],{'h=A','h=B'},'location','northwest','fontsize',12);
xlabel('x(mm)');
ylabel('y(mm)');
zlabel('z(mm)');
% For Top-view:-
h1=plot(x1,y1);
kk=boundary(x1,y1);
h11=patch(x1(kk),y1(kk),'r');
hold on
h2=plot(x2,y2);
kk=boundary(x2,y2);
h22=patch(x2(kk),y2(kk),'y');
alpha(0.25)
set(get(get(h1,'Annotation'),'LegendInformation'),'IconDisplayStyle','off');
set(get(get(h11,'Annotation'),'LegendInformation'),'IconDisplayStyle','off');
set(get(get(h2,'Annotation'),'LegendInformation'),'IconDisplayStyle','off');
set(get(get(h22,'Annotation'),'LegendInformation'),'IconDisplayStyle','off');

Answers (1)

Jaswanth
Jaswanth on 16 Oct 2024
Hi,
To achieve a combined isometric and top view of the 3D plot, you can use “subplot” function to place both views in the same figure.
For the top view, the “boundary” and “patch” functions can be used to create 2D projections of the 3D data on the XY-plane. The ‘FaceAlpha’ property is used to set the transparency of the patches for the top view to match the transparency in the isometric view.
Please refer to the following code on how you can modify your code to include both the isometric and top views:
% Create a figure with two subplots
figure;
% First subplot for the isometric view
subplot(1, 2, 1);
kkk = boundary(x1, y1, z1);
V1 = trisurf(kkk, x1, y1, z1, 'Facecolor', 'r', 'Edgecolor', 'none');
hold on;
kkk = boundary(x2, y2, z2);
V2 = trisurf(kkk, x2, y2, z2, 'Facecolor', 'y', 'Edgecolor', 'none');
alpha(0.25);
legend([V1 V2], {'h=A', 'h=B'}, 'location', 'northwest', 'fontsize', 12);
xlabel('x(mm)');
ylabel('y(mm)');
zlabel('z(mm)');
view(3); % Isometric view
title('Isometric View');
% Second subplot for the top view
subplot(1, 2, 2);
hold on;
kk = boundary(x1, y1);
h11 = patch(x1(kk), y1(kk), 'r', 'FaceAlpha', 0.25, 'EdgeColor', 'none');
kk = boundary(x2, y2);
h22 = patch(x2(kk), y2(kk), 'y', 'FaceAlpha', 0.25, 'EdgeColor', 'none');
xlabel('x(mm)');
ylabel('y(mm)');
axis equal;
title('Top View');
Kindly refer to the following MathWorks documentation to know more about the functions discussed above:
I hope the solution provided above is helpful.

Community Treasure Hunt

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

Start Hunting!