trimesh_samplepoints_numpy

compas.datastructures.trimesh_samplepoints_numpy(mesh, num_points=1000, return_normals=False)[source]

Compute sample points on a triangle mesh surface.

Parameters
  • mesh (Mesh) – A triangle mesh data structure.

  • num_points (int, optional) – The number of sample points.

  • return_normals (bool, optional) – If True, return the normals in addition to the sample points.

Returns

ndarray | tuple[ndarray, ndarray] – If return_normals is False, a numpy ndarray representing sampled points with dim = [num_points, 3]. If return_normals is True, the sample points and the normals.

References

1

Barycentric coordinate system, Available at https://en.wikipedia.org/wiki/Barycentric_coordinate_system

2

Efficient barycentric point sampling on meshes, arXiv:1708.07559

Examples

Make a triangle mesh.

>>> from compas.datastructures import Mesh
>>> hypar = Mesh.from_obj(compas.get('hypar.obj'))
>>> hypar.is_trimesh()
False
>>> hypar.quads_to_triangles()

Compute sample points.

>>> samples_pts, pts_normals = trimesh_samplepoints_numpy(hypar, 1000, True)
>>> # the x,y,z of sample points would be the following
>>> x, y, z = samples_pts[:,0], samples_pts[:,1], samples_pts[:,2]
>>> # the sample points added normal vector would be the following
>>> X, Y, Z = x + pts_normals[:,0] , y + pts_normals[:,1] , z + pts_normals[:,2]