Voxel export into stl file

11 views (last 30 days)
Hege
Hege on 27 Jun 2020
Commented: M.S. Khan on 28 Aug 2020
I developed 3D matric as per my intention as below and now I want to export it to a STL file and view it. As I am new to the Matlab I downloaded the code from https://uk.mathworks.com/matlabcentral/fileexchange/27733-converting-a-3d-logical-array-into-an-stl-surface-mesh?focused=5235499&tab=function (Used the convert voxels to stl example file) and tried to develop my function. But I could not successful as there was a error with a mat.file. I tried to rectify the mat.file issue.Still unsuccessful.
My SUCCESSFUL voxel code
% Building the 10X10X10 Voxel Cube
B=zeros(10,10,10);
B([1,10],:,:)=1;
B(:,[1,10],:)=1;
B(:,:,[1,10])=1;
nnz(B==1)
nnz(B==0)
My UNSUCCESSFUL voxel conversion to stl code
%Load an example dataset. The contents are as follows:
% gridDATA 30x30x30 216000 double array
% gridX 1x30 240 double array
% gridY 1x30 240 double array
% gridZ 1x30 240 double array
load ('cube.mat','B')
%Convert the binary data to an STL mesh:
[faces,vertices] = CONVERT_voxels_to_stl('temp.stl',gridINPUT,gridX,gridY,gridZ,'ascii');
%Plot the original data:
figure;
imagesc(squeeze(sum(gridINPUT,3)));
colormap(gray);
axis equal tight
%Load and plot the stl file:
figure
[stlcoords] = READ_stl('temp.stl');
xco = squeeze( stlcoords(:,1,:) )';
yco = squeeze( stlcoords(:,2,:) )';
zco = squeeze( stlcoords(:,3,:) )';
[hpat] = patch(xco,yco,zco,'b');
axis equal
Note== Always error in load command!!. I downloaded this code from the above link and trying to match for my work.
Appreciate your comments

Answers (1)

darova
darova on 28 Jun 2020
What about isosurface?
clc,clear
clf
r = 10;
[x,y,z] = meshgrid(-r:r);
v = x.^2+y.^2+z.^2<r^2;
h = isosurface(x,y,z,v,0.9);
patch(h,'facecolor','r')
axis vis3d
  1 Comment
M.S. Khan
M.S. Khan on 28 Aug 2020
Hi Darova, how i want to apply on cone. Please guide me. Regards

Sign in to comment.

Categories

Find more on Line Plots in Help Center and File Exchange

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!