Use Domain to Check Points Containment#
import minterpy as mp
import numpy as np
Once a Domain instance is constructed, it can be used to verify whether a given set of points lies within the domain.
This guide demonstrates how to carry out such a check.
Example: Three-dimensional rectangular domain#
Create a three-dimensional rectangular domain that corresponds to:
Domain instance#
The rectangular domain is defined by three pairs of bounds (each forms an interval) one for each dimension. We can specify them in a single two-dimensional array of three rows:
bounds = np.array([
[0.0, 5.0],
[10.0, 15.0],
[0.5, 3.0],
])
An instance of Domain given an array of bounds can be constructed using the default constructor:
dom = mp.Domain(bounds)
We can verify that the domain is three dimensional:
print(dom.spatial_dimension)
3
and with the appropriate bounds:
print(dom.bounds)
[[ 0. 5. ]
[10. 15. ]
[ 0.5 3. ]]
Check containment with respect to the user domain#
A set of points can be verified to lie within the user domain using the contains() method. For instance, to check if the following set of points
xx = np.array([
[0.1, 11.0, 1.75], # True
[0.4, 13, 2.75], # True
[-1, 11, 0.5], # False
[0.2, 16.0, 2.0], # False
])
lie within the domain:
dom.contains(xx)
array([ True, True, False, False])
Notice that the check is carried for each point.
Check containment with respect to the internal domain#
Alternatively, a set of points can also be verified to lie within the internal domain using the same method and passing internal=True argument. For instance, to check if the following set of points
xx = np.array([
[0.0, 0.0, 0.0], # True
[-1, -1, -1], # True
[-0.75, 0.75, 0.5], # True
[-2, -2, 2], # False
])
lie within the internal domain:
dom.contains(xx, internal=True)
array([ True, True, True, False])
Once again, notice that the check is carried for each point.