scenic.core.vectors

Scenic vectors and vector fields.

Summary of Module Members

Functions

alwaysGlobalOrientation

Whether this orientation is always aligned with the global coordinate system.

makeVectorOperatorHandler

scalarOperator

Decorator for vector operators that yield scalars.

vectorDistributionMethod

Decorator for methods that produce vectors.

vectorOperator

Decorator for vector operators that yield vectors.

zeroIdentityVectorOperator

zeroPreservingVectorOperator

Classes

Orientation

An orientation in 3D space.

OrientedVector

PiecewiseVectorField

A vector field defined by patching together several regions.

PolygonalVectorField

A piecewise-constant vector field defined over polygonal cells.

PolyhedronVectorField

Vector

A 3D vector, whose coordinates can be distributions.

VectorDistribution

A distribution over Vectors.

VectorField

A vector field, providing an orientation at every point.

VectorMethodDistribution

Vector version of MethodDistribution.

VectorOperatorDistribution

Vector version of OperatorDistribution.

Member Details

class VectorDistribution(*dependencies, valueType=None)[source]

Bases: Distribution

A distribution over Vectors.

_defaultValueType

alias of Vector

class VectorOperatorDistribution(operator, obj, operands)[source]

Bases: VectorDistribution

Vector version of OperatorDistribution.

class VectorMethodDistribution(method, obj, args, kwargs)[source]

Bases: VectorDistribution

Vector version of MethodDistribution.

scalarOperator(method)[source]

Decorator for vector operators that yield scalars.

vectorOperator(method, preservesZero=False, zeroIdentity=False)[source]

Decorator for vector operators that yield vectors.

vectorDistributionMethod(method)[source]

Decorator for methods that produce vectors. See distributionMethod.

class Orientation(rotation)[source]

An orientation in 3D space.

classmethod fromQuaternion(quaternion)[source]

Create an Orientation from a quaternion (of the form (x,y,z,w))

Return type:

Orientation

classmethod fromEuler(yaw, pitch, roll)[source]

Create an Orientation from yaw, pitch, and roll angles (in radians).

Return type:

Orientation

property yaw: float

Yaw in the global coordinate system.

property pitch: float

Pitch in the global coordinate system.

property roll: float

Roll in the global coordinate system.

property eulerAngles: Tuple[float, float, float]

Global intrinsic Euler angles yaw, pitch, roll.

localAnglesFor(orientation)[source]

Get local Euler angles for an orientation w.r.t. this orientation.

That is, considering self as the parent orientation, find the Euler angles expressing the given orientation.

Return type:

Tuple[float, float, float]

globalToLocalAngles(yaw, pitch, roll)[source]

Convert global Euler angles to local angles w.r.t. this orientation.

Equivalent to localAnglesFor but takes Euler angles as input.

Return type:

Tuple[float, float, float]

alwaysGlobalOrientation(orientation)[source]

Whether this orientation is always aligned with the global coordinate system.

Returns False if the orientation is a distribution or delayed argument, since then the value cannot be known at this time.

class Vector(x, y, z=0)[source]

Bases: Samplable, Sequence

A 3D vector, whose coordinates can be distributions.

sphericalCoordinates()[source]

Returns this vector in spherical coordinates (rho, theta, phi)

rotatedBy(angleOrOrientation)[source]

Return a vector equal to this one rotated counterclockwise by angle/orientation.

Return type:

Vector

angleWith(other)[source]

Compute the signed angle between self and other.

The angle is positive if other is counterclockwise of self (considering the smallest possible rotation to align them).

Return type:

float

class VectorField(name, value, minSteps=4, defaultStepSize=5)[source]

A vector field, providing an orientation at every point.

Parameters:
  • name (str) – name for debugging.

  • value – function computing the heading at the given Vector.

  • minSteps (int) – Minimum number of steps for followFrom; default 4.

  • defaultStepSize (float) – Default step size for followFrom; default 5. This is an upper bound: more steps will be taken as needed to ensure that no single step is longer than this value, but if the distance to travel is small then the steps may be smaller.

followFrom(pos, dist, steps=None, stepSize=None)[source]

Follow the field from a point for a given distance.

Uses the forward Euler approximation, covering the given distance with equal-size steps. The number of steps can be given manually, or computed automatically from a desired step size.

Parameters:
  • pos (Vector) – point to start from.

  • dist (float) – distance to travel.

  • steps (int) – number of steps to take, or None to compute the number of steps based on the distance (default None).

  • stepSize (float) – length used to compute how many steps to take, or None to use the field’s default step size.

static forUnionOf(regions, tolerance=0)[source]

Creates a PiecewiseVectorField from the union of the given regions.

If none of the regions have an orientation, returns None instead.

class PolygonalVectorField(name, cells, headingFunction=None, defaultHeading=None)[source]

Bases: VectorField

A piecewise-constant vector field defined over polygonal cells.

Parameters:
  • name (str) – name for debugging.

  • cells – a sequence of cells, with each cell being a pair consisting of a Shapely geometry and a heading. If the heading is None, we call the given headingFunction for points in the cell instead.

  • headingFunction – function computing the heading for points in cells without specified headings, if any (default None).

  • defaultHeading – heading for points not contained in any cell (default None, meaning reject such points).

class PiecewiseVectorField(name, regions, tolerance=0, defaultHeading=None)[source]

Bases: VectorField

A vector field defined by patching together several regions.

The heading at a point is determined by checking each region in turn to see if it has an orientation and contains the point, returning the corresponding heading if so. If we get through all the regions, and tolerance is nonzero, we try again, this time allowing the point to be up to tolerance away from each region. If we still fail to find a region “containing” the point, then we return the defaultHeading, if any, and otherwise reject the scene.

Parameters:
  • name (str) – name for debugging.

  • regions (sequence of Region objects) – the regions making up the field.

  • tolerance (float) – maximum distance at which to consider a point as being in one of the regions, if it is not otherwise contained (default 0).

  • defaultHeading (float) – the heading for points not in any region with an orientation (default None, meaning reject such points).