Shape Definitions

Shape definitions contain information about the shape of individual particles. Some shapes define a type_shape property, which returns a dict for consumption by visualization tools. The type_shape specification can be found here: Shape Visualization.

class garnett.shapes.FallbackShape[source]

This shape definition class is used when no specialized Shape class can be applied.

The fallback shape definition is a string containing the definition.

class garnett.shapes.Shape(shape_class=None, color=None)[source]

Parent class of all shape objects.

Parameters:
  • shape_class (str) – Shape class directive, used for POS format (default: None).
  • color (str) – Hexadecimal color string in format RRGGBBAA (default: None).
pos_string
type_shape
class garnett.shapes.SphereShape(diameter, orientable=False, color=None)[source]

Shape class for spheres of a specified diameter.

Parameters:
  • diameter (float) – Diameter of the sphere.
  • orientable (bool) – Set to True for spheres with orientation (default: False).
  • color (str) – Hexadecimal color string in format RRGGBBAA (default: None).
pos_string
type_shape

Shape as dictionary. Example:

>>> SphereShape(2.0).type_shape
{'type': 'Sphere', 'diameter': 2.0}
class garnett.shapes.ArrowShape(thickness=0.1, color=None)[source]

Shape class for arrows of a specified thickness.

Parameters:
  • thickness (float) – Thickness of the arrow.
  • color (str) – Hexadecimal color string in format RRGGBBAA (default: None).
pos_string
type_shape
class garnett.shapes.SphereUnionShape(diameters, centers, colors=None)[source]

Shape class for sphere unions, such as rigid bodies of many spheres.

Parameters:
  • diameters (list) – List of sphere diameters.
  • centers (list) – List of 3D center vectors.
  • colors (list) – List of hexadecimal color strings in format RRGGBBAA (default: None).
pos_string
type_shape

Shape as dictionary. Example:

>>> SphereUnionShape([0.5, 0.5, 0.5], [[0, 0, 1.0], [0, 1.0, 0], [1.0, 0, 0]]).type_shape
{'type': 'SphereUnion', 'diameters': [0.5, 0.5, 0.5],
 'centers': [[0, 0, 1.0], [0, 1.0, 0], [1.0, 0, 0]]}
class garnett.shapes.PolygonShape(vertices, color=None)[source]

Shape class for polygons in a 2D plane.

Parameters:
  • vertices (list) – List of 2D vertex vectors.
  • color (str) – Hexadecimal color string in format RRGGBBAA (default: None).
pos_string
type_shape

Shape as dictionary. Example:

>>> PolygonShape([[-0.5, -0.5], [0.5, -0.5], [0.5, 0.5]]).type_shape
{'type': 'Polygon', 'rounding_radius': 0,
 'vertices': [[-0.5, -0.5], [0.5, -0.5], [0.5, 0.5]]}
class garnett.shapes.SpheropolygonShape(vertices, rounding_radius=0, color=None)[source]

Shape class for rounded polygons in a 2D plane.

Parameters:
  • vertices (list) – List of 2D vertex vectors.
  • rounding_radius (float) – Rounding radius applied to the spheropolygon (default: 0).
  • color (str) – Hexadecimal color string in format RRGGBBAA (default: None).
pos_string
type_shape

Shape as dictionary. Example:

>>> SpheropolygonShape([[-0.5, -0.5], [0.5, -0.5], [0.5, 0.5]], 0.1).type_shape
{'type': 'Polygon', 'rounding_radius': 0.1,
 'vertices': [[-0.5, -0.5], [0.5, -0.5], [0.5, 0.5]]}
class garnett.shapes.ConvexPolyhedronShape(vertices, color=None)[source]

Shape class for convex polyhedra.

Parameters:
  • vertices (list) – List of 3D vertex vectors.
  • color (str) – Hexadecimal color string in format RRGGBBAA (default: None).
pos_string
type_shape

Shape as dictionary. Example:

>>> ConvexPolyhedronShape([[0.5, 0.5, 0.5], [0.5, -0.5, -0.5],
                           [-0.5, 0.5, -0.5], [-0.5, -0.5, 0.5]]).type_shape
{'type': 'ConvexPolyhedron', 'rounding_radius': 0,
 'vertices': [[0.5, 0.5, 0.5], [0.5, -0.5, -0.5],
              [-0.5, 0.5, -0.5], [-0.5, -0.5, 0.5]]}
class garnett.shapes.ConvexPolyhedronUnionShape(vertices, centers, orientations, colors=None)[source]

Shape class for unions of convex polyhedra.

Parameters:
  • vertices (list) – List of lists of 3D vertex vectors in particle coordinates (each polyhedron, each vertex).
  • centers (list) – List of 3D polyhedra center vectors.
  • orientations (list) – Orientations of the polyhedra, as a list of quaternions.
  • colors (list) – List of hexadecimal color strings in format RRGGBBAA (default: None).
pos_string
type_shape
class garnett.shapes.ConvexSpheropolyhedronShape(vertices, rounding_radius=0, color=None)[source]

Shape class for a convex polyhedron extended by a rounding radius.

Parameters:
  • vertices (list) – List of 3D vertex vectors.
  • rounding_radius (float) – Rounding radius applied to the spheropolyhedron (default: 0).
  • color (str) – Hexadecimal color string in format RRGGBBAA (default: None).
pos_string
type_shape

Shape as dictionary. Example:

>>> ConvexSpheropolyhedronShape([[0.5, 0.5, 0.5], [0.5, -0.5, -0.5],
                                 [-0.5, 0.5, -0.5], [-0.5, -0.5, 0.5]], 0.1).type_shape
{'type': 'ConvexPolyhedron', 'rounding_radius': 0.1,
 'vertices': [[0.5, 0.5, 0.5], [0.5, -0.5, -0.5],
              [-0.5, 0.5, -0.5], [-0.5, -0.5, 0.5]]}
class garnett.shapes.GeneralPolyhedronShape(vertices, faces, color=None, facet_colors=None)[source]

Shape class for general polyhedra, such as arbitrary meshes.

Parameters:
  • vertices (list) – List of 3D vertex vectors.
  • faces (list) – List of lists of integers representing vertex indices for each face.
  • color (str) – Hexadecimal color string in format RRGGBBAA (default: None).
  • facet_colors (list) – List of hexadecimal color strings in format RRGGBBAA for each facet (default: None).
pos_string
type_shape

Shape as dictionary. Example:

>>> GeneralPolyhedronShape([[0.5, 0.5, 0.5], [0.5, -0.5, -0.5],
                            [-0.5, 0.5, -0.5], [-0.5, -0.5, 0.5]]).type_shape
{'type': 'Mesh',
 'vertices': [[0.5, 0.5, 0.5], [0.5, -0.5, -0.5],
              [-0.5, 0.5, -0.5], [-0.5, -0.5, 0.5]],
 'indices': [[0, 1, 2], [0, 1, 3], [0, 2, 3], [1, 2, 3]]}
class garnett.shapes.EllipsoidShape(a, b, c, color=None)[source]

Shape class for ellipsoids of with principal axes a, b, and c.

Parameters:
  • a (float) – Principal axis a of the ellipsoid (radius in the x direction).
  • b (float) – Principal axis b of the ellipsoid (radius in the y direction).
  • c (float) – Principal axis c of the ellipsoid (radius in the z direction).
  • color (str) – Hexadecimal color string in format RRGGBBAA (default: None).
pos_string
type_shape

Shape as dictionary. Example:

>>> EllipsoidShape(7.0, 5.0, 3.0).type_shape
{'type': 'Ellipsoid',
 'a': 7.0,
 'b': 5.0,
 'c': 3.0}