Obtain 3D shape cross section

10 ビュー (過去 30 日間)
Ahmed
Ahmed 2023 年 8 月 8 日
編集済み: DGM 2025 年 7 月 8 日 10:16
i have designed a part in CAD based software as shown in the image, this shape is extruded on the Z axis. I am looking for a way to import this geometry into MATLAB and select a specific Z offset from which i can obtain the points that make up the cross section at the Z offset. Additionally I would like to seperate the points into an outer and inner groups and order the points in a way that if plotted they connect to draw the accurate cross section with no intersections.
I have tried importing the shape as an stl file and then i obtain the points at the desired Z offset by getting the intersetcions of the triangles generated from the mesh at the Z offset, however the points obtained are not in order and adapting the nearest point algorithm isnt sufficient to correct the order for any random geometry.
  1 件のコメント
Daniel Bengtson
Daniel Bengtson 2023 年 8 月 8 日
If this example is representative of the shapes that you are working with, could you convert the points that you have into polar coordinates then just sort by theta? Thresholding between the outer and inner boundary could probably be done by clustering rho.

サインインしてコメントする。

回答 (2 件)

Gojo
Gojo 2023 年 9 月 6 日
Hey @Ahmed,
Building on the idea suggested by @Daniel Bengtson in the comments, You can separate the inner and outer points by various ways:
  1. Clustering the points
  2. Using any known feature or shape that your CAD model provides to get the threshold value to categorize between inner and outer points.
  3. You can visually inspect the cross-section and adjust the threshold until it separates the points correctly.
  4. Calculate the distance between each point and the centroid of the cross-section. Set the threshold based on the mean distance from the centroid of cross section (average of points) to all other intersection points.
After separating the points into inner points and outer points, You can order them based on their angle. Take one point and centroid as a reference and calculate angles of other points and sort them.
Hope this helps!!

DGM
DGM 2025 年 7 月 8 日 7:58
編集済み: DGM 2025 年 7 月 8 日 10:16
Sorting model vertices by z-position is not a practical solution. There is no reason to assume that model vertices are anywhere near the query position, especially for a simple extrusion.
Consider the following model. There are only two z-values among the vertex data, 0 and 1. If you're picking points from the vertex data, that's the only place you can section the model.
Consider this model. It's much the same story; there are vertices only on the top and bottom faces. Note also that the vertices along the upper outside edge are closer to their neighbors on the inside edge than they are to their neighbors on the outside edge. That means a naive presumption about connectivity being implied by distance would fail. Note that there are no intermediate vertices along the radial edges. That means that any sort of clustering based on distance from centroid would also fail.
See this example based on triangle-triangle intersection:
This example will slice a triangulated model at specified z-levels, and it will return a polyshape array. If you only need the boundary curves, they can be obtained from the polyshape object(s). At the very least, the code is an example of processing the edge data returned from the underlying tools, so you're free to roll your own.
That said, if we know that the model is a simple extrusion with no taper or sectional geometry change over its height, then we don't actually need to section it at any intermediate position. The end faces already describe the sectional geometry by themselves. Just isolate that portion of the F,V data and use it. If you need nothing other than the open edges, convert it to a triangulation object, and then call freeBoundary() on it. If you want to calculate the area, then getting the edges isn't what you want.
For example:
% the triangulated surface
unzip annularspacer15.stl.zip
T = stlread('annularspacer15.stl');
[F V] = t2fv(T);
% preview display
patch('faces',F,'vertices',V,'facecolor','w','edgecolor','none','facealpha',1);
view(3); view(-34,28); camlight;
axis equal; grid on
% select the upper faces by whatever means is appropriate
goodv = V(:,3) > 0; % this is sufficient for the given model
[Ft Vt] = prunebadverts(F,V,goodv); % get rid of everything else
% just the top faces
figure
patch('faces',Ft,'vertices',Vt,'facecolor','w','edgecolor','k','facealpha',1);
axis equal; grid on
% if you just want the boundaries, get the boundaries.
% getting the boundaries isn't helpful if we want the area.
Tt = triangulation(Ft,Vt);
boundaries = freeBoundary(Tt);
% if you want the area, get the area from _the triangles_.
A = sum(triarea(Vt,Ft))
A = 131.8945

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by