mindscience.data.Polygon

class mindscience.data.Polygon(name, vertices, boundary_type='uniform', dtype=numpy.float32, sampling_config=None)[source]

Definition of polygon object.

Parameters
  • name (str) – Name of the polygon.

  • vertices (numpy.ndarray) – Vertices of the polygon in an anti-clockwise order.

  • boundary_type (str) –

    This can be 'uniform' or 'unweighted'. Default: 'uniform'.

    • 'uniform', the expected number of samples in each boundary is proportional to the area (length) of the boundary.

    • 'unweighted', the expected number of samples in each boundary is the same.

  • dtype (numpy.dtype) – Data type of sampled point data type. Default: numpy.float32.

  • sampling_config (SamplingConfig) – Sampling configuration. Default: None.

Examples

>>> from mindscience.data import generate_sampling_config, Polygon
>>> polygon_mesh = dict({'domain': dict({'random_sampling': True, 'size': 300}),
...                      'BC': dict({'random_sampling': True, 'size': 300, 'with_normal': False,}),})
>>> vertices = np.array([[0., 0], [1, 0], [1, 1], [.5, 1], [0.5, 0.5], [0, 0.5]])
>>> polygon = Polygon("polygon", vertices,
...                   sampling_config=generate_sampling_config(polygon_mesh))
>>> domain = polygon.sampling(geom_type="domain")
>>> bc = polygon.sampling(geom_type="bc")
>>> print(domain.shape)
(300, 2)