pycapacity.objects

Overview

There two genertic classes implemented in this module:

  • Polytope: A generic class representing a polytope with different representations (vertex, half-plane, face)

  • Ellipsoid: A generic class representing an ellipsoid with a list of radii and rotation matrix

class pycapacity.objects.Ellipsoid(radii=None, rotation=None, center=None)[source]

Bases: object

A generic class representing an ellipsoid with a list of radii and rotation matrix, where every column of the rotation matrix is a vector of the ellipsoid’s axes

\[\mathcal E = \{x ~|~ x^T R^T W R x \leq 1 \}\]

where \(W = diag(r_1^{-2}, r_2^{-2}, \ldots, r_n^{-2})\) and \(r_i\) are radii of the ellipsoid, while \(R\) is the rotation matrix

Variables:
  • center – ellipsoid center

  • radii – radii of the ellipsoid

  • rotation – rotation of the ellipsoid SO3 matrix

class pycapacity.objects.Polytope(vertices=None, faces=None, face_indices=None, H=None, d=None)[source]

Bases: object

A generic class representing a polytope with different representations (vertex, half-plane, face)

Vertex representation is a list of vertices of the polytope

\[\mathcal{H}\!-\!rep = \{x \in \mathbb{R}^n | Hx \leq d \}\]

Half-plane representation is a list of inequalities defining the polytope

\[\mathcal{V}\!-\!rep = \{x_{v1},~ x_{v2},~ \ldots, ~x_{vn} \}\]

Face representation is a list of triangles forming faces of the polytope, each triangle is represented as a list of tree vertices

\[\mathcal{F}\!-\!rep = \{ [x_{v1},~ x_{v2}, ~x_{v2}], ~ \ldots , ~[x_{vi},~ x_{vj}, ~x_{vk}], \ldots \}\]
Variables:
  • vertices – vertex representation of the polytope

  • H – half-plane representation of the polytope Hx<d - matrix H

  • d – half-plane representation of the polytope Hx<d- vector d

  • faces – face representation of the polytope - faces are represented as a list of triangulated vertices

  • face_indices – face representation of the polytope - faces are represented as a list of indices of vertices

Polytope object implements the following operators:

  • + : minkowski sum of two polytopes

  • & : intersection of two polytopes

Examples

>>> from pycapacity.objects import *
>>> import numpy as np
>>> # create a polytope object
>>> p = Polytope(vertices=np.random.rand(3,10))
>>> # find half-plane representation of the polytope
>>> p.find_halfplanes()
>>> # find face representation of the polytope
>>> p.find_faces()
>>> # find vertex representation of the polytope
>>> p.find_vertices()
>>> # create another polytope object
>>> p1 = Polytope(vertices=np.random.rand(3,10))
>>> # minkowski sum of two polytopes
>>> p_sum = p + p1
>>> # intersection of two polytopes
>>> p_int = p & p1

Additionally for robot’s force polytopes will have additional attributes:

  • torque_vertices: (if applicable) joint torques corresponding to the vertices of the polytope

Additionally for human’s force polytopes will have additional attributes:

  • torque_vertices: (if applicable) joint torques corresponding to the vertices of the polytope

  • muscle_forces_vertices: (if applicable) muscle forces corresponding to the vertices of the polytope

Human’s velocity polytopes will have additional attributes:

  • dq_vertices: (if applicable) joint velocities corresponding to the vertices of the polytope

  • dl_vert: (if applicable) muscle elongation velocities corresponding to the vertices of the polytope

chebyshev_ball()[source]

Function calculating the Chebyshev ball of the polytope, the largest ball that can be inscribed in the polytope. The function calculates the center and radius of the ball and returns an ellipsoid object representing the Chebyshev ball of the polytope

Th function uses one Linear Programming problem to find the Chebyshev ball of the polytope. See also: https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.HalfspaceIntersection.html#r9b902253b317-1

Returns:

an ellipsoid object representing the Chebyshev ball of the polytope

Return type:

Ellipsoid(Ellipsoid)

find_faces()[source]

A function calculating the face representation of the polytope from the vertex representation

find_from_point_cloud(points)[source]

A function updating the polytope object from a point cloud it calculates the vertex and half-plane representation of the polytope.

Note

The polytope will be constructed as a convex hull of the point cloud

Parameters:

points (np.array) – an array of points forming a point cloud

find_halfplanes()[source]

A function calculating the half-plane representation of the polytope from the vertex representation

find_vertices()[source]

A function calculating the vertex representation of the polytope from the half-plane representation