trimesh_samplepoints_numpy

compas.datastructures.trimesh_samplepoints_numpy(mesh: compas.datastructures.mesh.core.mesh.BaseMesh, num_points: int = 1000, return_normals: bool = False)Union[numpy.ndarray, Tuple[numpy.ndarray, numpy.ndarray]][source]

Compute sample points on a triangle mesh surface

Parameters
  • mesh (compas.datastructures.Mesh) – Mesh is limited to triangle mesh

  • num_points ((int)) – How many points sampled

  • return_normals ((bool)) – if True, return the normals vector of sampled points

Returns

  • samples_points(numpy.ndarray) – A numpy ndarray representing sampled points with dim = [num_points, 3]

  • (if True) samples_points_normals(numpy.ndarray) – A numpy ndarray representing the normal vector of sampled points with dim = [num_points, 3]

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]

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