pyransame.random_vertex_points#
- pyransame.random_vertex_points(mesh: DataSet, n: int = 1, weights: str | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | None = None) ndarray #
Generate random points from vertices.
Note
This function is provided for completeness of API, but it is likely faster and more flexible to use a custom method.
Supported cell types:
Vertex
PolyVertex
- Parameters:
- meshpyvista.DataSet
The mesh for which to generate random points. Must have cells.
- nint, default: 1
Number of random points to generate.
- weightsstr, or array_like, optional
Weights to use for probability of choosing points inside each cell.
If a
str
is supplied, it will use the existing cell data onmesh
.
- Returns:
- pointsnp.ndarray
(n, 3)
points that exist inside cells onmesh
.
Examples
Create a mesh with 1 vertex cell (1 point) and 1 polyvertex cell (5 points).
>>> import pyransame >>> import pyvista as pv >>> p = [ ... [0., 0., 0.], ... [1., 0., 0.], ... [1., 1., 0.], ... [1., 2., 0.], ... [1., 3., 0.], ... [1., 4., 0.], ... ] >>> mesh = pv.PolyData(p, verts=[1, 0, 5, 1, 2, 3, 4, 5]) >>> points = pyransame.random_vertex_points(mesh, n=3)
Now plot result.
>>> pl = pv.Plotter() >>> _ = pl.add_mesh(mesh, render_points_as_spheres=True, point_size=16.0, color='blue') >>> _ = pl.add_points(points, render_points_as_spheres=True, point_size=20.0, color='red') >>> pl.view_xy() >>> pl.show()