Help with using scanf and editing a txt file?
Show older comments
I'm trying to modify an stl file to eventually 3D print. I am trying to take out the bottom half of the object by using matlab. Essentially, I converted the stl file to .txt so I can analyze the z values to cut away the bottom half. I am trying to use the scanf function or something like it to read the vertices of the triangles, find max and min of xyz, and delete triangles if z<(zmax+zmin)/2. How can I accomplish this?
6 Comments
KSSV
on 20 Jul 2018
This can be done..it depends on how your file is...show us your file...
Taylor Gates
on 20 Jul 2018
You're going to struggle with sscanf, I'd use one or more regex personally. I presume it's a whole facet you'd want to remove if your condition is met, everything from facet normal ... to endfacet ?
I did not understand the condition you want to use to eliminate facets. Can you be clearer (e.g. with a concrete numerical example)?
edit: Actually, the first thing you should do is search the FileExchange to see if there isn't an stl reader and writer. Assuming it has been decently written, it should be a lot more reliable than writing your own parser.
Taylor Gates
on 20 Jul 2018
Guillaume
on 20 Jul 2018
Assuming that we have code to read the vertices (it's not too hard to write that efficiently) that produces for example a Nfacet x Nvertices x 3 matrix. How do you decide which facets to remove? Mathematically.
Taylor Gates
on 20 Jul 2018
Accepted Answer
More Answers (0)
Categories
Find more on STL (STereoLithography) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!