# random_points_on_mesh

## `random_points_on_mesh(V, F, n, rng=np.random.default_rng(), color='white', per_element_likelihood=None, return_indices=False)`

Samples a mesh V,F according to a given distribution. Valid meshes are polylines or triangle meshes.

Parameters:

Name Type Description Default
`V` `(n_v,d) numpy array`

vertex list of vertex positions

required
`F` `(m,k) numpy int array`

if k==2, interpret input as ordered polyline; if k==3 numpy int array, interpred as face index list of a triangle mesh

required
`rng` `numpy rng, optional (default: new `np.random.default_rng()`)`

which numpy random number generator to use

`default_rng()`
`n` `int`

how many points to sample

required
`color`

"Noise color" of the distribution used for sampling. Right now, only "white" is supported, which corresponds to a uniform distribution.

`'white'`
`per_element_likelihood`

If given, the likelihood of sampling a point from each element (does not need to be normalized). If not given, all elements are equally likely.

`None`
`return_indices` `bool, optional (default: False)`

Whether to return the indices for each element along with the barycentric coordinates of the sampled points within each element

`False`

Returns:

Name Type Description
`x` `(n,d) numpy array`

the n sampled points

`I` `(n,) numpy int array`

element indices where sampled points lie (if requested)

`u` `(n,k) numpy array`

barycentric coordinates for sampled points in I

Examples:

TODO

Source code in `src/gpytoolbox/random_points_on_mesh.py`
 ``` 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80``` ``````def random_points_on_mesh(V,F, n, rng=np.random.default_rng(), color='white', per_element_likelihood=None, return_indices=False): """Samples a mesh V,F according to a given distribution. Valid meshes are polylines or triangle meshes. Parameters ---------- V : (n_v,d) numpy array vertex list of vertex positions F : (m,k) numpy int array if k==2, interpret input as ordered polyline; if k==3 numpy int array, interpred as face index list of a triangle mesh rng : numpy rng, optional (default: new `np.random.default_rng()`) which numpy random number generator to use n : int how many points to sample color: str "Noise color" of the distribution used for sampling. Right now, only "white" is supported, which corresponds to a uniform distribution. per_element_likelihood: (m,) numpy double array, optional (default: None) If given, the likelihood of sampling a point from each element (does not need to be normalized). If not given, all elements are equally likely. return_indices : bool, optional (default: False) Whether to return the indices for each element along with the barycentric coordinates of the sampled points within each element Returns ------- x : (n,d) numpy array the n sampled points I : (n,) numpy int array element indices where sampled points lie (if requested) u : (n,k) numpy array barycentric coordinates for sampled points in I Examples -------- TODO """ if per_element_likelihood is None: per_element_likelihood = np.ones(F.shape[0]) assert n>=0 assert color=='white', "Only white noise is supported right now" if n==0: if return_indices: return np.zeros((0,), dtype=V.dtype), \ np.zeros((0,), dtype=F.dtype), \ np.zeros((0,), dtype=V.dtype) else: return np.zeros((0,), dtype=V.dtype) k = F.shape[1] if k==2: I,u = _uniform_sample_polyline(V,F,n,rng,per_element_likelihood) x = u[:,0][:,None]*V[F[I,0],:] + \ u[:,1][:,None]*V[F[I,1],:] elif k==3: I,u = _uniform_sample_triangle_mesh(V,F,n,rng,per_element_likelihood) x = u[:,0][:,None]*V[F[I,0],:] + \ u[:,1][:,None]*V[F[I,1],:] + \ u[:,2][:,None]*V[F[I,2],:] else: assert False, "Only polylines and triangles supported" if return_indices: return x, I, u else: return x ``````