How do you rescaling an STL surface in Matlab?

조회 수: 18 (최근 30일)
Alice Bologni
Alice Bologni 2021년 2월 1일
답변: Vaibhav 2023년 10월 12일
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

답변 (1개)

Vaibhav
Vaibhav 2023년 10월 12일
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!

카테고리

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