def delaunay3d(pyptlist, tolerance = 1e-06):
"""
This function constructs a mesh (list of triangle OCCfaces) from a list of points. Currently only works for two dimensional points.
Parameters
----------
pyptlist : a list of tuples
The list of points to be triangulated. A pypt is a tuple that documents the xyz coordinates of a pt e.g. (x,y,z),
thus a pyptlist is a list of tuples e.g. [(x1,y1,z1), (x2,y2,z2), ...]
tolerance : float, optional
The minimal surface area of each triangulated face, Default = 1e-06.. Any faces smaller than the tolerance will be deleted.
Returns
-------
list of face : list of OCCfaces
A list of meshed OCCfaces (triangles) constructed from the meshing.
"""
import numpy as np
from scipy.spatial import Delaunay
pyptlistx = []
pyptlisty = []
pyptlistz = []
for pypt in pyptlist:
pyptlistx.append(pypt[0])
pyptlisty.append(pypt[1])
pyptlistz.append(pypt[2])
# u, v are parameterisation variables
u = np.array(pyptlistx)
v = np.array(pyptlisty)
x = u
y = v
z = np.array(pyptlistz)
# Triangulate parameter space to determine the triangles
tri = Delaunay(np.array([u,v]).T)
occtriangles = []
xyz = np.array([x,y,z]).T
for verts in tri.simplices:
pt1 = list(xyz[verts[0]])
pt2 = list(xyz[verts[1]])
pt3 = list(xyz[verts[2]])
occtriangle = make_polygon([pt1,pt2,pt3])
tri_area = calculate.face_area(occtriangle)
if tri_area > tolerance:
occtriangles.append(occtriangle)
return occtriangles
#========================================================================================================
#EDGE INPUTS
#========================================================================================================
评论列表
文章目录