Skip to main content

MATLAB code to get SLICE profile

 The below code is written in MATLAB it gives the coordinates when any object in an STL file is sliced at a desired height.

Input: STL file.

Output: Slice profile at a given height.  


clc;
clear all;
FV = stlread('A3.stl');  %d the stl file 
[F,V,N]=stlread('A3.stl');  %d Reading Stl file
sz= F.Points;   %d Reading the cordinates 

ma= max(sz(:,3));
mi= min(sz(:,3));

disp('Z must be between');
disp(ma); disp('and') ;disp(mi);



z= input('Enter Z height:');
km= F.ConnectivityList;
l=size(km);
i=l(1);
ka=1;

for j=1:i
    
    p=km(j,1); q=km(j,2); r=km(j,3);
    k1=sz(p,3); k2=sz(q,3); k3=sz(r,3);
    g1= max([k1,k2,k3]);
     g2= min([k1,k2,k3]);

            if ((g2<=z) & (z<=g1))
                
                  
                       if  ((sz(p,3)<=z) & (z<=sz(q,3)) | ((sz(q,3)<=z) & (z<=sz(p,3))))
                           
                             m= ((z-sz(p,3))/((sz(q,3)-sz(p,3))));
                             x(ka)=((m*((sz(q,1)-(sz(p,1)))))+(sz(p,1)));
                             y(ka)=((m*((sz(q,2)-(sz(p,2)))))+(sz(p,2)));
                             
                           ka=ka+1;
                       end 
                       
                       if  ((sz(p,3)<=z) & (z<=sz(r,3)) | ((sz(r,3)<=z) & (z<=sz(p,3))))
                           
                             m= ((z-sz(p,3))/((sz(r,3)-sz(p,3))));
                             x(ka)=((m*((sz(r,1)-(sz(p,1)))))+(sz(p,1)));
                             y(ka)=((m*((sz(r,2)-(sz(p,2)))))+(sz(p,2)));
                             
                           ka=ka+1;
                       end 
                       
                       if  ((sz(q,3)<=z) & (z<=sz(r,3)) | ((sz(r,3)<=z) & (z<=sz(q,3))))
                           
                             m= ((z-sz(q,3))/((sz(r,3)-sz(q,3))));
                             x(ka)=((m*((sz(r,1)-(sz(q,1)))))+(sz(q,1)));
                             y(ka)=((m*((sz(r,2)-(sz(q,2)))))+(sz(q,2)));
                             
                           ka=ka+1;
                       end 
                
            end


j=j+1;
end
plot(x,y);

Comments

Popular posts from this blog

Classification of Additive Manufacturing (3D printing)

Gyroid Structure

The below code written in the MATLAB® can be used for generating the Gyroid structure.  %% Program clc; clear all; n1 = 2;  % Number of cells in x Direction n2 = 2;  % Number of cells in y Direction n3 = 2; % Number of cells in z Direction   a=2*n1*pi; % x direction parameters b=2*n2*pi; % y direction parameters g=2*n3*pi;  % z direction parameters   s=0.01;   [x,y,z]=meshgrid(-0.5:s:0.5,-0.5:s:0.5,-0.5:s:0.5);   % Gyroid Formula u = (sin(a.*x).* cos(b.*y) + sin(b.*y).* cos(g.*z) + sin(g.*z).* cos(a.*x));   % Level Set equation c =0.7; Ts= -(u+c).*(u-c);    % Sheet based Gyroid Tsk= u + c;        % Skeletal based Gyroid Isosurface(x,y,z,Ts,0); Isocaps(x,y,z,Ts,0); %% Program Ends If very less knowledge about coding, then the below software can be used for generating Gyroid and other lattice structures. Using Lattice_Karak  helps in designing v...

Generating Lattice Structures

Lattice structures are getting lots of momentum in various fields due to their eccentric properties [1] . It is very important to have easy method to design these lattice structures. Lattice_Karak [2] helps in getting the work done. It is free software with UI made for students and researchers. Using Lattice_Karak  helps in designing various TPMS structures, export them into stl file for further processing like 3D printing and Finite Element analysis.   Lattice_Karak can be downloaded using the below link. https://drive.google.com/file/d/1WWL-UbPzErFCFVFJqw1as9w0M61aMxB4/view?usp=sharing   Videos on how to further use lattice_karak. https://youtu.be/CuHQwsxPa3I   https://sites.google.com/iith.ac.in/lattice-karak/home   Suggested materials for understanding more about TPMS: 1)      https://doi.org/10.1016/j.addma.2017.12.006 2)      https://doi.org/10.1016/j.matdes.2017.03.018 3)      https://doi.org/10...