pycapacity.objects
Overview
There two genertic classes implemented in this module:
- class pycapacity.objects.Ellipsoid(radii=None, rotation=None, center=None)[source]
Bases:
objectA 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:
objectA generic class representing a polytope with different representations (vertex, half-plane, face)
Vertex representation is a list of vertices of the polytope
\[\mathcal{V}\!-\!rep = \{x_{v1},~ x_{v2},~ \ldots, ~x_{vn} \}\]Half-plane representation is a list of inequalities defining the polytope
\[\mathcal{H}\!-\!rep = \{x \in \mathbb{R}^n | Hx \leq d \}\]Face representation is a list of triangles forming faces of the polytope, each triangle is represented as a list of three vertices
\[\mathcal{F}\!-\!rep = \{ [x_{v1},~ x_{v2}, ~x_{v3}], ~ \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 (p1 + p2) or translation by a vector (p + x)-: translation by a vector (p - x)*: scaling by a scalar (2 * p)@: linear image of the polytope by a matrix (R @ p)&: intersection of two polytopes
and the methods
contains(points),volume(),reduce()(minimal representations),chebyshev_ball()andPolytope.from_points(points)(convex hull of a point cloud).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
- contains(points, tol=1e-09)[source]
Check if points are inside the polytope (using the half-plane representation)
- Parameters:
points (np.array) – one point (vector) or points as columns (dimension x number of points)
tol (float) – tolerance on the inequalities (relative to the size of the polytope)
- Returns:
True for the points inside the polytope
- Return type:
bool or np.array of bool
- property dim
dimension of the space the polytope lives in
- 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. One convex hull is computed: the vertices are the extreme points of the cloud, the half-plane representation has one inequality per facet and the faces are triangulated (see
pycapacity.algorithms.convex_hull_representations()).- 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
- classmethod from_points(points)[source]
Polytope given as the convex hull of a point cloud (vertices, half-planes and face indices are computed)
- Parameters:
points (np.array) – points as columns (dimension x number of points)
- Returns:
the convex hull of the points
- Return type:
- reduce()[source]
Make the representations of the polytope minimal: only the extreme points as vertices, one inequality per facet (the redundant inequalities, for example after an intersection, are removed), and the corresponding triangulated faces.
- Returns:
the polytope itself (for chaining)
- Return type: