Save 3d surface plot as u3d or .ply file
10 views (last 30 days)
Show older comments
Hello, I am having trouble in saving my matlab interactive 3d plot as u3d or .ply file.
I am unable to understand the file exchange: https://www.mathworks.com/matlabcentral/fileexchange/25383-matlab-mesh-to-pdf-with-3d-interactive-object.
Any help wor alternative would be greatly appreciated.
Below is my sample code.
%% Plotting the curve to be reflected
clear all
close all
clc
% Constants
I0 = 1; % Initial X-ray beam intensity
rCu = 405; % radius of copper wire, um
rPMMA = 25; % radius of the PMMA, um
lamda = 7.1255e-5; % x-ray wavelength, um, (17400 eV)
k = 2*pi/lamda; % wavenumber, um^-1
beta_Cu = 2.5914E-07; % https://henke.lbl.gov/optical_constants/
beta_PMMA = 5.0314E-10; % https://henke.lbl.gov/optical_constants/
%Xray
mu_Cu = 0.076E-4;
mu_PMMA = 4.165E-4
%% Computing intensity versus x-position
%I(x)= I0*exp(−(µCu*LCu(x)+µPMMA*LPMMA(x))]
%Assume wire long axis is along z-axis, with center at x=0.
%Assume x-rays travel in y direction.
rT=rCu+rPMMA; % Total radius of the copper wire ,um
x=(-2:.04:1.98)*rT; %x values (um) (range = +-2*rT)
t_Cu=2*sqrt(max(rCu^2-x.^2,0));
t_total=2*sqrt(max(rT^2-x.^2,0));
t_PMMA=t_total-t_Cu;
It=exp(-mu_Cu*t_Cu-mu_PMMA*t_PMMA);
Iab = 1-It;
%% Guass
xstart=-2;
xstop=2;
xpoints=100;
xinc=(xstop-xstart)/(xpoints-1);
ystart=-2;
ystop=2;
ypoints=100;
yinc=(xstop-xstart)/(xpoints-1);
for ii=1:xpoints
x(ii)=xstart+xinc*(ii-1);
for jj=1:ypoints
y(jj)=ystart+yinc*(jj-1);
z=x(ii)*x(ii)+y(jj)*y(jj);
Is(ii,jj)=exp(-z);
end
end
% figure(2)
% plot(Is)
%% Detector intensity
M=It.*Is;
figure(3)
% subplot(211)
Z=log(M);
M=mesh(M)
title('Transmission plot','FontSize',13)
% xlabel('$x (\mumm)$','interpreter','latex')
ylabel('$length (\mu m)$','interpreter','latex')
zlabel('$Detector Intensity$ (arb.)','interpreter','latex')
view([-4 12])
% Create textbox
% Create textbox
annotation('textbox',...
[0.733097718253965 0.811081794195249 0.0877356150793676 0.0360912174896386],...
'String','Wire radius = 430 \mum',...
'FontWeight','bold',...
'FitBoxToText','off',...
'BackgroundColor',[1 0 0]);
% Create textbox
annotation('textbox',...
[0.730363343253966 0.767810026385223 0.108699156746034 0.0300226159065249],...
'String','Coating thickness = 80 \mum',...
'FontWeight','bold',...
'FitBoxToText','off',...
'BackgroundColor',[1 0 0]);
% VMRL export
%%
%% Absorption
Iabs=Iab.*Is;
0 Comments
Answers (1)
Deep
on 27 Dec 2024
Edited: Deep
on 27 Dec 2024
To save a 3D surface plot as a .PLY file from your given "Surface" object "M", you can use the "pcwrite" function (https://www.mathworks.com/help/vision/ref/pcwrite.html) as shown below:
% Create a Nx3 matrix for N points
[XGrid, YGrid] = meshgrid(M.XData, M.YData);
xyzPoints = [XGrid(:), YGrid(:), M.ZData(:)];
% Create a point cloud object and save as .PLY
p = pointCloud(xyzPoints);
pcwrite(p, 'object3d.ply');
For saving your plot as a U3D file, the File Exchange link you mentioned converts the mesh data to an IDTF format, which is then transformed into a U3D file using third-party software. The face data required for this conversion is available in the properties of the "Surface" object "M". You can refer to the MATLAB documentation for more details: https://www.mathworks.com/help/matlab/ref/matlab.graphics.chart.primitive.surface-properties.html#buch_5e_sep_shared-FaceNormals.
For practical guidance, check the "demo_mesh2pdf.m" file included in the File Exchange link that you mentioned.
0 Comments
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!