Help with using scanf and editing a txt file?

조회 수: 5 (최근 30일)
Taylor Gates
Taylor Gates 2018년 7월 20일
편집: Guillaume 2018년 7월 20일
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
Guillaume
Guillaume 2018년 7월 20일
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
Taylor Gates 2018년 7월 20일
I'm pretty new to matlab and programming so I am still working on a code to read the vertices. Do you have any guidance towards that?

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
Guillaume 2018년 7월 20일
편집: Guillaume 2018년 7월 20일
This is how I'd read all the vertices.
%assumptions:
% all vertices are made of 3 coordinates
% all faces are made of 3 vertices
%the code completely ignore the non-vertex lines
lines = strsplit(fileread('thinker.txt'), \n'); %read whole file and split into lines
vertlines = strjoin(lines(startsWith(lines, 'vertex')), '\n'); %identify vertex lines and rejoin
vertices = reshape(sscanf(vertlines, 'vertex %f%f%f\n'), 3, 3, []); %read vertices coordinates and reshape into something useful
This will give you a 3 x Nvertex x Nfacet matrix.
As you've not explained what filtering you want to do after that, I can't help you further.
  댓글 수: 1
Taylor Gates
Taylor Gates 2018년 7월 20일
Thank you. So should I come up with a max allowable z value to input to filter out all the others. Essentially I am just trying to cut away the bottom half of the image and I know that will be done through the z values. So would I come up with a range of acceptable z values?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 STL (STereoLithography)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by