Question is how do I use meshmixer and matlab to extract the bottom 50% of an st
ID: 3916699 • Letter: Q
Question
Question is how do I use meshmixer and matlab to extract the bottom 50% of an stl file. My assignment is posted below.
You can see the attached STL file (Headless Thinker) with a free STL viewer, Meshmixer.
https://www.meshmixer.com/download.html
Rename the attached as Thinker.txt and read the data only, using scanf command.
Find the z-coord range (height) of the statue, and remove the bottom 50%.
Re-create ThinkerHalf.STL using fprintf command.
See lecture slide 12-16
Hint:
(1) The first and last line should be kept as it is.
First line: solid Exported from Blender-2.79 (sub 0)
Last line: endsolid Exported from Blender-2.79 (sub 0)
(2) The STL file is repetition of 7 lines that defines many triangles.
First line (facet normal) is the direction vector of the triangle,
and 3-5 lines are the (x,y,z) of triangle vertex. You should find and delete triangles whose vertex z-coordinate is below a critical z value. See my video lecture for more details.
Explanation / Answer
please give thumbs up. thanks
CODE :
% open stl file
fid = fopen('Thinker.txt');
fgetl(fid);
data = fscanf(fid,' facet normal %e %e %e outer loop vertex %e %e %e vertex %e %e %e vertex %e %e %e endloop endfacet ');
%close file
fclose(fid);
%extract x
node_x = data(1:3:length(data));
%extract y
node_y = data(2:3:length(data));
%extract z
node_z = data(3:3:length(data));
%remove those are less than threshold
th=(max(node_z)*50)/100;
for i=length(node_z):-4:1
if(node_z(i)<th || node_z(i-1)<th ||node_z(i)<th)
node_z(i)=[];
node_z(i)=[];
node_z(i)=[];
node_z(i)=[];
node_y(i)=[];
node_y(i)=[];
node_y(i)=[];
node_y(i)=[];
node_x(i)=[];
node_x(i)=[];
node_x(i)=[];
node_x(i)=[];
end
end
%write to file
x=length(node_x)+length(node_y)+length(node_z);
j=1;
for i=1:3:x
v(i)=node_x(j);
v(i+1)=node_y(j);
v(i+2)=node_z(j);
fid = fopen('vishal.stl','w');
for i=1:4:length(node_x)
fprintf(fid,'facet normal %f %f %f outer loop vertex %f %f %f vertex %f %f %f vertex %f %f %f endloop endfacet ',node_x(i),node_y(i),node_z(i),node_x(i+1),node_y(i+1),node_z(i+1),node_x(i+2),node_y(i+2),node_z(i+2),node_x(i+3),node_y(i+3),node_z(i+3));
end
end
%close file
fclose(fid);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.