pycapacity.objectsο
Overviewο
There two genertic classes implemented in this module:
- 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
- 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