STL Label faces (F), vertices (V) and normals (N)

20 次查看(过去 30 天)
Hello,
I have attached a simple cube. I would like to label the faces (F), vertices (V) and normals (N) of this STL file in the image. If possible I would like to limit the labels to just one of the faces. For example just the face with the face with the vertices 1, 2 and 3.
Can you show me how to do it?
Thank you :D
Edit: This is my code (more or less) and attached are the right files, the matlab figure and the stl file
Edit 2: I've corrected the code to show the edges.
FileName = 'Cube_3d_printing_sample.stl'
OpenFile= stlread(FileName);
[F, V, N] = stlread(FileName);
patch(OpenFile, ...
'FaceColor', [0.1 0.5 0.2], ...
'FaceLighting', 'gouraud', ...
'FaceAlpha', 1, ...
'EdgeColor', 'black', ...
'EdgeLighting', 'gouraud', ...
'EdgeAlpha', 1, ...
'AmbientStrength', 0.9);
camlight headlight
material shiny
axis image
axis on
view([45 20]);
xlabel ('x-Achse')
ylabel ('y-Achse')
zlabel ('z-Achse')
  2 个评论
Diego Hens
Diego Hens 2020-8-24
Thanks, I've edited the question and added the stl file and the right figure. I've also written my code, just in case.

请先登录,再进行评论。

回答(1 个)

Rahul
Rahul 2025-5-14
I understand that you wish to add labels individually to faces, vertices and normals on your 3d model. Consider the following:
  • Since 'stlread' function returns a triangluation object. Consider obtaining the 'F', 'V' using the 'ConnectivityList', 'Points' property of the triangulation object. Consider obtaining the 'N' using the 'FaceNormal' function by adding the triangulation object as an argument.
  • After obtaining 'F', 'V' and 'N', for vertices use the 'text' function to insert text in the plot based on their coordinates.
  • For labelling the faces, use 'F' to obtain the centroid of the face using the 'mean' function and the 'text' function to insert the label at the location of the centroid.
  • For labelling the Normals, use 'N' and the centoid of faces calculated. Use the 'quiver3' function if an arrow is to be inserted and the 'text' function to insert the label at the location of the normal calculated.
Here is an example:
FileName = 'Cube_3d_printing_sample.stl';
TR = stlread(FileName);
F = TR.ConnectivityList;
V = TR.Points;
N = faceNormal(TR);
figure;
hold on; % Ensure everything is drawn on the same axes
patch('Faces',F,'Vertices',V, ...
'FaceColor', [0.1 0.5 0.2], ...
'EdgeColor', 'black', ...
'FaceAlpha', 0.5);
% Lighting and view
camlight headlight
material shiny
axis image
axis on
view([45 20]);
xlabel ('x-Achse')
ylabel ('y-Achse')
zlabel ('z-Achse')
faceIdx = 1; % Change to desired face index
faceVertsIdx = F(faceIdx, :);
faceVerts = V(faceVertsIdx, :);
faceNormals = N(faceIdx, :);
% Label vertices
for i = 1:3
vertIdx = faceVertsIdx(i);
vertCoord = faceVerts(i,:);
text(vertCoord(1), vertCoord(2), vertCoord(3), ...
sprintf('V%d', vertIdx), ...
'FontSize',12,'Color','blue','FontWeight','bold');
end
% Label face centroid
faceCentroid = mean(faceVerts,1);
text(faceCentroid(1), faceCentroid(2), faceCentroid(3), ...
sprintf('F%d', faceIdx), ...
'FontSize',12,'Color','red','FontWeight','bold');
% Plot and label normal
quiver3(faceCentroid(1), faceCentroid(2), faceCentroid(3), ...
faceNormals(1), faceNormals(2), faceNormals(3), ...
0.5, 'Color', 'magenta', 'LineWidth', 2, 'MaxHeadSize', 1);
normalTip = faceCentroid + 0.5*faceNormals;
text(normalTip(1), normalTip(2), normalTip(3), ...
sprintf('N%d', faceIdx), ...
'FontSize',12,'Color','magenta','FontWeight','bold');
hold off;
The following MathWorks documentations can be referred:
Thanks.

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by