scenic.core.regions

Objects representing regions in space.

Manipulations of polygons and line segments are done using the shapely package.

Summary of Module Members

Module Attributes

everywhere

A Region containing all points.

nowhere

A Region containing no points.

Functions

orientationFor

regionFromShapelyObject

Build a Region from Shapely geometry.

toPolygon

Classes

AllRegion

Region consisting of all space.

CircularRegion

A circular region with a possibly-random center and radius.

DifferenceRegion

EmptyRegion

Region containing no points.

GridRegion

A Region given by an obstacle grid.

IntersectionRegion

PointInRegionDistribution

Uniform distribution over points in a Region.

PointSetRegion

Region consisting of a set of discrete points.

PolygonalRegion

Region given by one or more polygons (possibly with holes).

PolylineRegion

Region given by one or more polylines (chain of line segments).

RectangularRegion

A rectangular region with a possibly-random position, heading, and size.

Region

Abstract class for regions.

SectorRegion

A sector of a CircularRegion.

Member Details

regionFromShapelyObject(obj, orientation=None)[source]

Build a Region from Shapely geometry.

class PointInRegionDistribution(*args, **kwargs)[source]

Bases: VectorDistribution

Uniform distribution over points in a Region.

class Region(name, *dependencies, orientation=None)[source]

Bases: Samplable

Abstract class for regions.

intersect(other)[source]

Get a Region representing the intersection of this one with another.

If both regions have a preferred orientation, the one of self is inherited by the intersection.

Return type

Region

intersects(other)[source]

Check if this Region intersects another.

Return type

bool

difference(other)[source]

Get a Region representing the difference of this one and another.

Return type

Region

union(other)[source]

Get a Region representing the union of this one with another.

Not supported by all region types.

Return type

Region

static uniformPointIn(region)[source]

Get a uniform Distribution over points in a Region.

uniformPointInner()[source]

Do the actual random sampling. Implemented by subclasses.

containsPoint(point)[source]

Check if the Region contains a point. Implemented by subclasses.

Return type

bool

containsObject(obj)[source]

Check if the Region contains an Object.

The default implementation assumes the Region is convex; subclasses must override the method if this is not the case.

Return type

bool

distanceTo(point)[source]

Distance to this region from a given point.

Not supported by all region types.

Return type

float

getAABB()[source]

Axis-aligned bounding box for this Region. Implemented by some subclasses.

orient(vec)[source]

Orient the given vector along the region’s orientation, if any.

class AllRegion(name, *dependencies, orientation=None)[source]

Bases: Region

Region consisting of all space.

class EmptyRegion(name, *dependencies, orientation=None)[source]

Bases: Region

Region containing no points.

everywhere = <AllRegion everywhere>

A Region containing all points.

Points may not be sampled from this region, as no uniform distribution over it exists.

nowhere = <EmptyRegion nowhere>

A Region containing no points.

Attempting to sample from this region causes the sample to be rejected.

class CircularRegion(center, radius, resolution=32, name=None)[source]

Bases: Region

A circular region with a possibly-random center and radius.

Parameters
  • center (Vector) – center of the disc.

  • radius (float) – radius of the disc.

  • resolution (int; optional) – number of vertices to use when approximating this region as a polygon.

  • name (str; optional) – name for debugging.

class SectorRegion(center, radius, heading, angle, resolution=32, name=None)[source]

Bases: Region

A sector of a CircularRegion.

This region consists of a sector of a disc, i.e. the part of a disc subtended by a given arc.

Parameters
  • center (Vector) – center of the corresponding disc.

  • radius (float) – radius of the disc.

  • heading (float) – heading of the centerline of the sector.

  • angle (float) – angle subtended by the sector.

  • resolution (int; optional) – number of vertices to use when approximating this region as a polygon.

  • name (str; optional) – name for debugging.

class RectangularRegion(position, heading, width, length, name=None)[source]

Bases: Region

A rectangular region with a possibly-random position, heading, and size.

Parameters
  • position (Vector) – center of the rectangle.

  • heading (float) – the heading of the length axis of the rectangle.

  • width (float) – width of the rectangle.

  • length (float) – length of the rectangle.

  • name (str; optional) – name for debugging.

class PolylineRegion(points=None, polyline=None, orientation=True, name=None)[source]

Bases: Region

Region given by one or more polylines (chain of line segments).

The region may be specified by giving either a sequence of points or shapely polylines (a LineString or MultiLineString).

Parameters
  • points – sequence of points making up the polyline (or None if using the polyline argument instead).

  • polylineshapely polyline or collection of polylines (or None if using the points argument instead).

  • orientation (optional) – preferred orientation to use, or True to use an orientation aligned with the direction of the polyline (the default).

  • name (str; optional) – name for debugging.

property start

Get an OrientedPoint at the start of the polyline.

The OP’s heading will be aligned with the orientation of the region, if there is one (the default orientation pointing along the polyline).

property end

Get an OrientedPoint at the end of the polyline.

The OP’s heading will be aligned with the orientation of the region, if there is one (the default orientation pointing along the polyline).

signedDistanceTo(point)[source]

Compute the signed distance of the PolylineRegion to a point.

The distance is positive if the point is left of the nearest segment, and negative otherwise.

Return type

float

pointAlongBy(distance, normalized=False)[source]

Find the point a given distance along the polyline from its start.

If normalized is true, then distance should be between 0 and 1, and is interpreted as a fraction of the length of the polyline. So for example pointAlongBy(0.5, normalized=True) returns the polyline’s midpoint.

Return type

Vector

class PolygonalRegion(points=None, polygon=None, orientation=None, name=None)[source]

Bases: Region

Region given by one or more polygons (possibly with holes).

The region may be specified by giving either a sequence of points defining the boundary of the polygon, or a collection of shapely polygons (a Polygon or MultiPolygon).

Parameters
  • points – sequence of points making up the boundary of the polygon (or None if using the polygon argument instead).

  • polygonshapely polygon or collection of polygons (or None if using the points argument instead).

  • orientation (VectorField; optional) – preferred orientation to use.

  • name (str; optional) – name for debugging.

property boundary: PolylineRegion

Get the boundary of this region as a PolylineRegion.

class PointSetRegion(name, points, kdTree=None, orientation=None, tolerance=1e-06)[source]

Bases: Region

Region consisting of a set of discrete points.

No Object can be contained in a PointSetRegion, since the latter is discrete. (This may not be true for subclasses, e.g. GridRegion.)

Parameters
  • name (str) – name for debugging

  • points (arraylike) – set of points comprising the region

  • kdTree (scipy.spatial.KDTree, optional) – k-D tree for the points (one will be computed if none is provided)

  • orientation (VectorField; optional) – preferred orientation for the region

  • tolerance (float; optional) – distance tolerance for checking whether a point lies in the region

class GridRegion(name, grid, Ax, Ay, Bx, By, orientation=None)[source]

Bases: PointSetRegion

A Region given by an obstacle grid.

A point is considered to be in a GridRegion if the nearest grid point is not an obstacle.

Parameters
  • name (str) – name for debugging

  • grid – 2D list, tuple, or NumPy array of 0s and 1s, where 1 indicates an obstacle and 0 indicates free space

  • Ax (float) – spacing between grid points along X axis

  • Ay (float) – spacing between grid points along Y axis

  • Bx (float) – X coordinate of leftmost grid column

  • By (float) – Y coordinate of lowest grid row

  • orientation (VectorField; optional) – orientation of region