Syntax
stlsolid(fid,VL,FL)
Input Parameter
fid : | | is the file identifyer of the file to write in, -1= screen |
VL : | | is the given list of vertexes |
FL : | | is the given list of facets |
Examples
Building a Tetraeder
p1=[1;0;0]; p2=[1;1;0]; p3=[0;1;0]; p4=[1;1;1];
VL=[p1 p2 p3 p4]';
FL=[1 3 2; 1 4 3; 1 2 4; 2 3 4];
stlsolid (-1,VL,FL)
Copyright 2010-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This function, stlsolid
, is designed to generate an STL file from a list of vertices and facets. It is part of the SG-Library and was created by Tim Lueth in 2010.
Input Parameters
- fid: The file identifier for the output file. If set to -1, the output is directed to the screen.
- VL: A matrix containing the list of vertices. Each row represents a vertex with its x, y, and z coordinates.
- FL: A matrix containing the list of facets. Each row represents a facet by specifying indices of the vertices that form the facet.
Algorithm Steps
- Determine the number of facets,
n
, using the size of the FL
matrix.
- Iterate over each facet from 1 to
n
:
- Extract the vertices
p1
, p2
, and p3
for the current facet using the indices from FL
.
- Calculate the normal vector
pn
for the facet using the cross product of vectors (p2-p1)
and (p3-p1)
.
- Normalize the normal vector
pn
.
- Write the facet normal and vertices to the output using
fprintf
:
- Output the normal vector with the format
'facet normal %f %f %f\n'
.
- Output the vertices within an
'outer loop'
structure, each with the format 'vertex %f %f %f \n'
.
- Close the loop with
'endloop'
and the facet with 'endfacet'
.
The function effectively writes the STL file in ASCII format, detailing each facet's normal and vertices.
Algorithm explaination created using ChatGPT on 2025-08-18 23:50. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21