How do you rescaling an STL surface in Matlab?

31 ビュー (過去 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 Center および File ExchangeSTL (STereoLithography) についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by