![](/img/trans.png)
[英]Save the Path2D as a .PNG or .JPEG from .to_planar() function of Trimesh Module in Python
[英]Find Properties of Polygons from Path2D, derived from the.to_planar() function of Trimesh Module in Python
使用 Python 中的 Trimesh 模塊,我可以從 STL 文件中獲取二維橫截面,代碼如下所示。
mesh = trimesh.load_mesh('MyFile.stl')
slicex = mesh.section(plane_origin=mesh.centroid, plane_normal=[0,30,0])
slice_2D, to_3D = slice.to_planar()
使用從上述代碼獲得的 2D 路徑 (Slice_2D),我可以將其中的多邊形作為 NumPy 數組獲取,並使用以下代碼對其進行迭代:
for polygon in slice_2D.polygons_closed:
trimesh.path.polygons.plot_polygon(polygon, show=True)
上面的代碼在控制台上顯示了多邊形。 但是,我想知道是否有辦法獲取多邊形的屬性,例如:多邊形中的邊數; 多邊形的周長和面積; 多邊形的類型(三角形或正方形或矩形或平行四邊形或圓形等)。
在這方面的任何幫助將不勝感激!
屬性“polygons_closed”返回一個形狀優美的多邊形數組。 所以得到即。 該地區,使用:
for polygon in slice_2D.polygons_closed:
trimesh.path.polygons.plot_polygon(polygon, show=True)
print(polygon.area)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.