How do you rescaling an STL surface in Matlab?

28 visualizaciones (últimos 30 días)
Alice Bologni
Alice Bologni el 1 de Feb. de 2021
Respondida: Vaibhav el 12 de Oct. de 2023
I have this code, but i don't managed to scale down the surface.
How do i do it?
Thank you
fv = stlread ( 'Femur_Head.stl' );
patch(fv,'FaceColor', [0.8 0.8 1.0], ...
'EdgeColor', 'none', ...
'FaceLighting', 'gouraud', ...
'AmbientStrength', 0.15);
% Add a camera light, and tone down the specular highlighting
camlight('headlight');
material('dull');
axis([-50 50 -50 50 0 80]);
view([-135 35]);
title('Femur Head');
xlabel('X');ylabel('Y');zlabel('Z');
% Fix the axes scaling, and set a nice view angle
axis('image');
view([-135 35]);
hold on

Respuestas (1)

Vaibhav
Vaibhav el 12 de Oct. de 2023
Hi Alice,
I understand that you would like to scale down the STL surface.
The following steps outline an approach that can be taken:
  • Retrieve vertices from the triangulation object:
vertices = fv.Points;
  • Determine the scale factor for each dimension (adjust as needed):
scaleFactor = 0.5; % Example: Decreases size by 50%
  • Scale the vertices:
scaledVertices = vertices * scaleFactor;
  • Plot the scaled STL:
trisurf(fv.ConnectivityList, scaledVertices(:, 1), scaledVertices(:, 2), scaledVertices(:, 3), 'FaceColor', [0.8 0.8 1.0], 'EdgeColor', 'none', 'FaceLighting', 'gouraud', 'AmbientStrength', 0.15);
The below code snippet demonstrates the scaling of the STL surface using "Torus.stl":
% Load STL file
fv = stlread('Torus.stl');
% Get the vertices from the triangulation object
vertices = fv.Points;
% Scale factor for each dimension (adjust as needed)
scaleFactor = 1.5; % Example: increase size by 50%
% Scale vertices
scaledVertices = vertices * scaleFactor;
% Plot the scaled STL
figure;
trisurf(fv.ConnectivityList, scaledVertices(:, 1), scaledVertices(:, 2), scaledVertices(:, 3), ...
'FaceColor', [0.8 0.8 1.0], 'EdgeColor', 'none', 'FaceLighting', 'gouraud', 'AmbientStrength', 0.15);
% Add lighting, adjust material properties, and set axis labels
camlight('headlight');
material('dull');
xlabel('X'); ylabel('Y'); zlabel('Z');
% Fix the axes scaling and set a nice view angle
axis('image');
view([-135 35]);
title('Scaled STL Surface');
Refer the below MathWorks documentations to know more about "stlread" and “trisurf”:
Hope this helps!

Community Treasure Hunt

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

Start Hunting!

Translated by