Union#

Module for Union class.

class Union(geometries)[source]#

Bases: OperationInterface

PINA implementation of Unions of Domains. Given two sets \(A\) and \(B\) then the domain difference is defined as:

\[A \cup B = \{x \mid x \in A \lor x \in B\},\]

with \(x\) a point in \(\mathbb{R}^N\) and \(N\) the dimension of the geometry space.

Parameters:

geometries (list) – A list of geometries from pina.geometry such as EllipsoidDomain or CartesianDomain.

Example:
>>> # Create two ellipsoid domains
>>> ellipsoid1 = EllipsoidDomain({'x': [-1, 1], 'y': [-1, 1]})
>>> ellipsoid2 = EllipsoidDomain({'x': [0, 2], 'y': [0, 2]})
>>> # Create a union of the ellipsoid domains
>>> union = GeometryUnion([ellipsoid1, ellipsoid2])
is_inside(point, check_border=False)[source]#

Check if a point is inside the Union domain.

Parameters:
  • point (LabelTensor) – Point to be checked.

  • check_border (bool) – Check if the point is also on the frontier of the ellipsoid, default False.

Returns:

Returning True if the point is inside, False otherwise.

Return type:

bool

sample(n, mode='random', variables='all')[source]#

Sample routine for Union domain.

Parameters:
  • n (int) – Number of points to sample in the shape.

  • mode (str) – Mode for sampling, defaults to random. Available modes include: random.

  • variables (str | list[str]) – Variables to be sampled, defaults to all.

Returns:

Returns LabelTensor of n sampled points.

Return type:

LabelTensor

Example:
>>> # Create two ellipsoid domains
>>> cartesian1 = CartesianDomain({'x': [0, 2], 'y': [0, 2]})
>>> cartesian2 = CartesianDomain({'x': [1, 3], 'y': [1, 3]})
>>> # Create a union of the ellipsoid domains
>>> union = Union([cartesian1, cartesian2])
>>> # Sample
>>> union.sample(n=5)
    LabelTensor([[1.2128, 2.1991],
                [1.3530, 2.4317],
                [2.2562, 1.6605],
                [0.8451, 1.9878],
                [1.8623, 0.7102]])
>>> len(union.sample(n=5)
    5