Physical objects#

Part#

class pyenki.PhysicalObject.Part#

Right prism that can be composed to define the geometry of a pyenki.PhysicalObject.

shape#

The convex 2D polygon (positively oriented) at the base of the prism [cm].

Type:

Sequence[Vector]

height#

The height [cm].

Type:

float

textures#

A list of textures: each texture is a list of colors for one vertical face of the prism. Must be either empty or have contains at least one color for each face.

Type:

Sequence[Sequence[Color]]

__init__(*args, **kwargs)#

Overloaded function.

  1. __init__(lx: SupportsFloat, ly: SupportsFloat, height: SupportsFloat) -> None

Creates a part with a rectangular base.

Parameters:
  • lx (float) – The x dimension [cm]

  • ly (float) – The y dimension [cm]

  • height (float) – The height [cm]

  1. __init__(shape: Sequence[Vector], height: SupportsFloat, textures: Sequence[Sequence[pyenki.Color]] = []) -> None

Creates a part with a polygonal base.

Parameters:
  • shape (Sequence[Vector]) – The convex 2D polygon (positively oriented) at the base of the prism [cm].

  • height (float) – The height [cm]

  • textures (Sequence[Sequence[Color]]) – A sequence of textures: each texture is a sequence of colors for one vertical face of the prism. Must be either empty or have contains at least one color for each face.

contains(point: Vector, tolerance: SupportsFloat = 0) bool#

PhysicalObject#

class pyenki.PhysicalObject#

The superclass of objects that can be simulated.

uid#

A unique identifier (readonly)

Type:

int

world#

The world the object belongs to (readonly)

Type:

World

has_collided#

Whether the object has collided in the last simulation step (readonly)

Type:

bool

name#

The name (readonly)

Type:

string

radius#

The radius of the object’s enclosing circle in centimeters (readonly)

Type:

float

height#

The object height in centimeters (readonly)

Type:

float

is_cylindric#

True if the object is cylindrical shaped (readonly)

Type:

bool

parts#

the parts the object is composed of.

Type:

list[PhysicalObject.Part]

mass#

The object mass in kilograms. If below zero, the object is static (readonly)

Type:

float

moment_of_inertia#

The object moment of inertial (readonly)

Type:

float

color#

The object color.

Type:

Color

collision_elasticity#

Elasticity of collisions of this object. If 0, soft collision, 100% energy dissipation; if 1, elastic collision, 0% energy dissipation. Actual elasticity is the product of the elasticity of the two colliding objects. Walls are fully elastics

Type:

float

dry_friction_coefficient#

The dry friction coefficient mu

Type:

float

viscous_friction_coefficient#

The viscous friction coefficient. Premultiplied by mass. A value of k applies a force of -k * speed * mass

Type:

float

viscous_moment_friction_coefficient#

The viscous friction moment coefficient. Premultiplied by momentOfInertia. A value of k applies a force of -k * speed * moment_of_inertia

Type:

float

position#

The position in the world frame in centimeters

Type:

Vector

angle#

The orientation in the world frame in radians

Type:

float

velocity#

The velocity in the world frame in centimeters per second

Type:

Vector

angular_speed#

The angular speed in the world frame in radians per second

Type:

float

collision_callback#

An optional function called when the object collides

def callback(PhysicalObject: obj1, PhysicalObject: obj2) -> None: ...

where obj1 and obj2 are the two objects that have just collided.

Type:

Callable[[PhysicalObject, PhysicalObject], None] | None

control_step_callback#

An optional function called when the object perform a control step

def callback(PhysicalObject: obj, time_step: bool) -> None: ...

with the same arguments as pyenki.PhysicalObject.control_step().

Type:

Callable[[PhysicalObject, float], None] | None

touch_callback#

An optional function called when touch events happen

def callback(PhysicalObject: obj, state: bool, button: int, x: float, y: float, z: float) -> None: ...

with the same arguments as pyenki.PhysicalObject.on_touch().

Type:

Callable[[PhysicalObject, bool, int, float, float, float], None] | None

__init__(*args, **kwargs)#

Overloaded function.

  1. __init__(parts: Sequence[pyenki.PhysicalObject.Part], mass: SupportsFloat, color: pyenki.Color = Color(r=0.0, g=0.0, b=0.0, a=1.0)) -> None

Creates an object composed of parts.

Parameters:
  1. __init__(radius: SupportsFloat, height: SupportsFloat, mass: SupportsFloat, color: pyenki.Color = Color(r=0.0, g=0.0, b=0.0, a=1.0)) -> None

Creates a cylinder.

Parameters:
  • radius (float) – The radius in cm.

  • height (float) – The height in cm.

  • mass (float) – The mass in kg.

  • color (Color) – The color.

  1. __init__(lx: SupportsFloat, ly: SupportsFloat, height: SupportsFloat, mass: SupportsFloat, color: pyenki.Color = Color(r=0.0, g=0.0, b=0.0, a=1.0)) -> None

Creates a rectangular prism.

Parameters:
  • lx (float) – the side length in cm (x).

  • ly (float) – the side length in cm (y).

  • height (float) – The height in cm.

  • mass (float) – The mass in kg.

  • color (Color) – The color.

  1. __init__(shape: Sequence[Vector], height: SupportsFloat, mass: SupportsFloat, color: pyenki.Color = Color(r=0.0, g=0.0, b=0.0, a=1.0), textures: Sequence[Sequence[pyenki.Color]] = []) -> None

Creates an vertical prism with a convex polygonal base.

Parameters:
  • shape (Sequence[Vector]) – The vertices polygonal base in cm. Must be convex.

  • height (float) – The height in cm.

  • mass (float) – The mass in kg.

  • color (Color) – The color.

  • textures (Sequence[Color]) – if not empty, defines the colors of each face.

contains(point: Vector, tolerance: SupportsFloat = 0) bool#
control_step(time_step: SupportsFloat) None#

The controller associated with the object.

Should be overridden by sub-classes to implement controllers, in particular for robots. Alternatively, users can assign a callback control_step_callback.

Parameters:

time_step (float) – The time step of the simulation.

on_touch(state: bool, button: SupportsInt, x: SupportsFloat, y: SupportsFloat, z: SupportsFloat) None#

Called after a touch event.

Can be overridden by sub-classes to react to touch events. Alternatively, users can assign a callback as touch_callback.

Parameters:
  • state (bool) – True for press, False for release.

  • button (int) – mouse button index: 0 (left), 1 (right) or 2 (middle).

  • x (float) – cursor x-coordinate (cm).

  • y (float) – cursor y-coordinate (cm).

  • z (float) – cursor z-coordinate (cm).

touch(state: bool, button: SupportsInt, x: SupportsFloat, y: SupportsFloat, z: SupportsFloat) None#

Trigger a touch event.

Parameters:
  • state (bool) – True for press, False for release.

  • button (int) – mouse button index: 0 (left), 1 (right) or 2 (middle).

  • x (float) – cursor x-coordinate (cm).

  • y (float) – cursor y-coordinate (cm).

  • z (float) – cursor z-coordinate (cm).

Warning

Textures are used to compute the sensors (cameras) response. They are displayed by the Python-based viewer/renderer but ignored by the native viewer/renderer.