Indiana University-Purdue University Indianapolis
You Are Viewing

Top3dSTL Archive

Top3dSTL Description


Top3dSTL   A simple STL writter for Top3d


Top3dSTL(fout) writes a STL file with name fout using cubic representation and binary file format if xPhys exists in Workspace.

Top3dSTL(fout, xPhys) writes a STL file with name fout using cubic representation and binary file format

Top3dSTL(___, Name, Value) writes a STL file with one or more Name, Value pair argments. Use this option with any of the input argument combinations in the prvious syntaxes.

FORMAT - File is written in 'binary' (default) or 'ascii' format.
TITLE - Header text (max 80 characters) written to the STL file.
MODE - Facets are generated using 'cube' (default) or 'iso'.
CUTOFF - Density cutoff value. default: 0.5
FACECOLOR - Face color. default: 'cyan'
ALPHA - Face alpha value. default: 1.
UNITLENGTH - Vector of element unit length. default: [1 1 1]
PLOT - Logic flag to display structures. default: true

Example 1:

Top3dSTL('MyTop3d.stl') % when xPhys is in Workspace

Example 2:

Top3dSTL('MyTop3d.stl', density, 'Format', 'ascii', 'Mode', 'iso', 'FaceColor', 'm', 'Plot', false)

STL File Format Specifications

Facet orientation

The facets define the surface of a 3-dimensional object. As such, each facet is part of the boundary between the interior and the exterior of the object. The orientation of the facets (which way is "out" and which way is "in") is specified redundantly in two ways which should be consistent. First, the direction of the normal is outward. Second, which is most commonly used now-a-day, list the facet vertexes in counter-clockwise order when looking at the object from the outside (right-hand rule).StL-facet

Vertex-to-vertex rule

Each triangle must share two vertices with each of its adjacent triangles. In other words, a vertex of one triangle cannot lie on the side of another.



An ASCII STL file begins with the line

solid name
where name is an optional string (though if name is omitted there must still be a space after solid).


The file continues with any number of triangles, each represented as follows:

facet normal ni nj nk
outer loop
vertex v1x v1y v1z
vertex v2x v2y v2z
vertex v3x v3y v3z

where each n or v is a floating-point number in sign-mantissa-"e"-sign-exponent format, e.g., "2.648000e-002" (noting that each v must be non-negative).


The file concludes with

endsolid name


Binary STL Format

The binary format uses the IEEE integer and floating point numerical representation.

The syntax for a binary STL file is as follows:

UINT8[80] – Header
UINT32 – Number of triangles

foreach triangle
REAL32[3] – Normal vector
REAL32[3] – Vertex 1
REAL32[3] – Vertex 2
REAL32[3] – Vertex 3
UINT16 – Attribute byte count




Top3dSTL Changelogs


Version 3.0

6 April 2015 In previous version, facets are generated more than they actually needed. For a matrix with 1x2x1 elements, Ver2.0 will generate 24 facets. However only 20 facets are required since two elements are sharing two same facets.  

Version 2.0

1 April 2015 Combines two programs (Top3dSTL_Cube, Top3dSTL_ISO) into a single program.  

Version 1.0

1 Feb 2015 Top3dSTL_Cube with 105 lines of MATLAB code. Top3dSTL_ISO with 81 lines of MATLAB code.

Top3dSTL Archived Versions