What are the variables for STL file conversion

5 views (last 30 days)
What are the X, Y, Z variables to use SURF2STL function? I do not have any of such variables. My goal is to create a stl file so that the model can be 3D printed. I have successfully drawn the model using surf function, but I can’t convert this to STL file.
Original file is a tiff file.
inFile = '/filepath/s04_e037_1arc_v3.tif';
% Creating figure
figure1 = figure
% Reading the tiff file
[Z,R]=geotiffread(inFile);
% Changing Z from int16 to double
Zedited = cast(Z, 'double');
% Limit lat and long for area
LATLIM=[-4.2,-2.8]
LONLIM=[36.8,38.2]
% Construct map axes for region
worldmap(LATLIM, LONLIM)
% Renaming title
title('Figure mountain','FontSize',18);
% Locating the values <= 0 for Zedited
ridzero = find(Zedited<=0);
% Changing the values of 0 to NaN in the vector
Znew=[Zedited];
Znew([ridzero]) = NaN;
% Displaying map data
geoshow(Znew, R, 'DisplayType', 'surface');
% Color the map based on the terrain elevation data, Znew.
% 888 is the number of colours used to colour from min to max elevation.
demcmap(Znew, 888);
% Resizing plot
set(gcf, 'Position', get(0, 'Screensize'));
% I want to create model! Create new figure for surface file
figure2 = figure
% More defined 3D surface to convert to STL/OBJ format for 3D printing!
surf(Znew,'EdgeColor','none','FaceColor','red')
% I do not know the X Y Z variables to convert to STL file type...
% surf2stl('modelsurf.stl',Znew,R,R)

Accepted Answer

KSSV
KSSV on 12 Sep 2018
Edited: KSSV on 12 Sep 2018
[nx,ny] = size(Znew) ;
[X,Y] = meshgrid(1:ny,1:nx) ;
Z = Znew ;
Now you have X,Y,Z..you can write them into .stl file.
  1 Comment
Madlab
Madlab on 14 Sep 2018
Thank you KSSV. I managed to create my STL file using the variables you suggested.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!