aspsim.room.region.Rectangle

class aspsim.room.region.Rectangle(side_lengths, center, point_spacing=(1, 1), spatial_dim=3, rng=None)

Bases: Region

Constructs a two-dimensional rectangle

The rectangle can be placed in 3D space by setting a 3-dimensional center

Parameters:
  • side_lengths (array_like of shape (2,)) – Lengths of the sides of the rectangle.

  • center (array_like of shape (2,) or (3,)) – Center of the cylinder. The length of the array determines the spatial dimension. If the array has length 3, the rectangle is placed in 3D space with the z-coordinate fixed at the value of the third element.

  • point_spacing (array_like of shape (2,), optional) – Spacing between points in each direction, affects the selection of points for the equally_spaced_points method. The default is (1,1,1).

  • spatial_dim (int, optional) – Spatial dimension of the rectangle. The default is 3. Must correspond to the length of the center array.

  • rng (np.random.Generator, optional) – Random number generator. The default is None, in which case a new generator with a random seed will be created. The generator affects the sampling of points in the sample_points method, and so should be supplied for a reproducible result.

Returns:

rectangle

Return type:

Rectangle

Notes

Although there are many more rectangles in 3D, here only rectangles with a fixed z-coordinate is considered. A rotation could in principle be applied to the rectangle for other orientations.

__init__(side_lengths, center, point_spacing=(1, 1), spatial_dim=3, rng=None)

Constructs a two-dimensional rectangle

The rectangle can be placed in 3D space by setting a 3-dimensional center

Parameters:
  • side_lengths (array_like of shape (2,)) – Lengths of the sides of the rectangle.

  • center (array_like of shape (2,) or (3,)) – Center of the cylinder. The length of the array determines the spatial dimension. If the array has length 3, the rectangle is placed in 3D space with the z-coordinate fixed at the value of the third element.

  • point_spacing (array_like of shape (2,), optional) – Spacing between points in each direction, affects the selection of points for the equally_spaced_points method. The default is (1,1,1).

  • spatial_dim (int, optional) – Spatial dimension of the rectangle. The default is 3. Must correspond to the length of the center array.

  • rng (np.random.Generator, optional) – Random number generator. The default is None, in which case a new generator with a random seed will be created. The generator affects the sampling of points in the sample_points method, and so should be supplied for a reproducible result.

Returns:

rectangle

Return type:

Rectangle

Notes

Although there are many more rectangles in 3D, here only rectangles with a fixed z-coordinate is considered. A rotation could in principle be applied to the rectangle for other orientations.

Methods

__init__(side_lengths, center[, ...])

Constructs a two-dimensional rectangle

equally_spaced_points()

Returns a grid of points within the region

is_in_region(coordinates[, padding])

Checks whether the coordinate is within the region or not.

plot(ax[, label])

sample_points(num_points)

Returns a set of points sampled uniformly within the region

equally_spaced_points()

Returns a grid of points within the region

Returns:

all_points – The number of points returned is determined by the radius, height and point_spacing. Each row is a coordinate in 3D or 2D space.

Return type:

np.ndarray of shape (num_points, 3) or (num_points, 2)

is_in_region(coordinates, padding=[[0, 0]])

Checks whether the coordinate is within the region or not.

Parameters:
  • coordinates (np.ndarray) – Shape (N,3) or (N, 2) where N is the number of coordinates to check. Each row is a coordinate in 3D space.

  • padding (array_like of shape (2,), optional) – Padding to add to the region. The default is [[0,0]]. This can be used to check whether a point is near the region, rather than strictly inside it.

Returns:

is_in – True if the coordinate is within the region, False otherwise.

Return type:

boolan np.ndarray of shape (N,)

sample_points(num_points)

Returns a set of points sampled uniformly within the region

Parameters:

num_points (int) – Number of points to sample.

Returns:

points – Each row is a coordinate in 3D or 2D space.

Return type:

np.ndarray of shape (num_points, 3) or (num_points, 2)