Hope all is well with you today! I had a question in creating a structure for a .STL traingle . For back ground information I have attached the link, the first two paragraphs and the ASCII STL part is what is revelant.
My question here is, I have to create a structure for the representation of the triangle below. Mathematically I understand what to do, put the pseudo code below is confusing me as I do not know how to represent it in c++.
For example, the pseudo code below represents one triangle but multiple triangles are needed to be created using the structure below so am guessing the "outer loop part" does that. But am confused how to represent this structure in c++. Any suggestions from you will be extremely helpful to me. Thank you once again for you time and if you do not understand anything do let me know.
An example for a code would be perfect.
1 2 3 4 5 6 7
facet normal ni nj nk
outer loop
vertex v1x v1y v1z
vertex v2x v2y v2z
vertex v3x v3y v3z
endloop
endfacet
code below represents one triangle but multiple triangles are needed to be created using the structure below so am guessing the "outer loop part" does that.
No. That "code" is one "facet" entry. One facet entry describes exactly one triangle. The link that you did provide does quite clearly say that a file can contain unknown number of facet entries.
For example, if the file has three triangles, it could look like this:
solid foo
facet normal ni nj nk
outer loop
vertex v1x v1y v1z
vertex v2x v2y v2z
vertex v3x v3y v3z
endloop
endfacet
facet normal ni nj nk
outer loop
vertex v1x v1y v1z
vertex v2x v2y v2z
vertex v3x v3y v3z
endloop
endfacet
facet normal ni nj nk
outer loop
vertex v1x v1y v1z
vertex v2x v2y v2z
vertex v3x v3y v3z
endloop
endfacet
endsolid foo
The n[ijk] and v[123][xyz] must be numbers.
Both normals and vertices are basically 3-element arrays. One triangle has one normal and three vertices. The data structure that you have to create depends on what you need to do with the data. For example, if you have to draw the triangles, then the graphics engine that you will use probably prefers input in particular format and you could design your data structure to support that.