Repeating multi-input function on tall array

Hi All,
I’ll preface by saying that this is the first project I’ve worked on which isn’t a lesson or demonstration which I have modified, so I am thoroughly out of my depth in terms of my own knowledge of Matlab.
I am making a system which will process STl files, and as part of it, I need to calculate the surface area of every facet.
First, a bit of terminology for those unfamiliar: In the context of 3d modelling, a facet is the smallest unit that a model is made up of when prepared for fabrication. This is almost always a triangle made by three points in a (x,y,z) cartesian coordinate system.
I am using an ascii STL(wikipedia for more info), which, for demonstration purposes, is a sphere I made openSCAD. I’m using the ‘stlReadAscii’ function from the ‘stlTools’ toolbox built by Pao Micó, the outputs for the demo file are attached, in case it is helpful. I am using it to slim down the full file to only the coordinates, which when isolated is a 3x4788 list, with the columns being XYZ, and the rows being individual points. Keep in mind that this is only a demo solid, the models I would actually be using this with could easily have upwards of 150 000 points, with three rows each. It may be worth noting that I made a slight modification to the ‘stlReadAscii’ function, making it so that it doesn’t get rid of duplicated points.
To calculate the area of a triangle, I need to pull from 3 rows, using the function:
sqrt((((Y2-Y1)*(Z3-Z1)-(Y3-Y1)*(Z2-Z1))^2) - (((X2-X1)*(Z3-Z1)-(X3-X1)*(Z2-Z1))^2) + (((X2-X1)*(Y3-Y1)-(X3-X1)*(Y2-Y1))^2))/2
Which is the longhand for a 3x3 determinant of the vectors between two of the points, divided by 2 to make the area of the inscribed triangle.
I am sure I could do this with the det function and clever calling to make the vectors, but I would run into the same issue of needing to move a ‘front’ of values to call forward by three rows continually. I just haven’t sat down and done that yet, and doing it longhand is closer to what I am used to doing.
In summary, I need to call from three different rows, and only give one output. Ideally, I would also like to index these outputs. Separately, I will need to index the facets, which I am also not sure how do do properly. (My first instinct is to create an additional column which would read 1 for the first three, 2 for the second three and so on, but I am sure there is a more efficient and effective approach.)
Thanks for any insight you can provide!

Respuestas (0)

Productos

Versión

R2019b

Preguntada:

el 29 de Mzo. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by