stlread
Reads a triangulated surface from an STL file.
Category: Mathematics > Computational Geometry
Syntax
TR = stlread(filename)
Reads a binary or ASCII STL file and returns a triangulation.
Description
STL stores each triangle with its three corners written out in full, so a vertex shared by many triangles appears many times in the file. stlread merges identical corners into one point, producing a proper indexed mesh. The order of points can differ from the order in which the writer produced them.
STL carries only geometry: no colors, units or vertex data. Face normals stored in the file are not kept in the result; use faceNormal to compute them.
Input arguments
filename- Name of the STL file, as a character vector or string.
Output arguments
TR- A 3-D
triangulationwithPoints(the distinct vertices) andConnectivityList(one triangle per row).
Example
Write and read back a tetrahedron
P = [0 0 0; 1 0 0; 0 1 0; 0 0 1];
T = [1 3 2; 1 2 4; 1 4 3; 2 3 4];
stlwrite(triangulation(T, P), 'tet.stl');
TR = stlread('tet.stl');
size(TR.Points)
size(TR.ConnectivityList)
ans = 1×2
4 3
ans = 1×2
4 3
Notes
stlread returns a single triangulation object. The multi-output form [F, V] raises an error; use TR.ConnectivityList and TR.Points for the faces and vertices.