Motions

This module contains functionality related to motions (continuous flexes).

class pyrigi.motion.ApproximateMotion(framework, steps, step_size=0.1, chosen_flex=0, tolerance=1e-05, fixed_pair=None, fixed_direction=None, pinned_vertex=None)[source]

Bases: Motion

Class representing an approximated motion of a framework.

When constructed, motion samples, i.e., realizations approximating a continuous flex of a given framework, are computed.

Definitions

Continuous flex (motion)

Parameters:
  • framework (Framework) – A framework whose approximation of a continuous flex is computed.

  • steps (int) – The amount of retraction steps that are performed. This number is equal to the amount of motion samples that are computed.

  • step_size (float) – The step size of each retraction step. If the output seems too jumpy or instable, consider reducing the step size.

  • chosen_flex (int) – An integer indicating the i-th flex from the list of Framework.inf_flexes() for i=chosen_flex.

  • tolerance (float) – Tolerance for the Newton iteration.

  • fixed_pair (tuple[Hashable, Hashable] | list[Hashable]) – Two vertices of the underlying graph that are fixed in each realization. By default, the first entry is pinned to the origin and the second is pinned to the x-axis.

  • fixed_direction (Sequence[int | float | str]) – Vector to which the first direction is fixed. By default, this is given by the first and second entry of fixed_pair.

  • pinned_vertex (Hashable) – If the keyword fixed_pair is not set, we can use the keyword pinned_vertex to pin one of the vertices to the origin instead during the motion.

Examples

>>> from pyrigi import ApproximateMotion
>>> from pyrigi import graphDB as graphs
>>> motion = ApproximateMotion.from_graph(
...     graphs.Cycle(4),
...     {0:(0,0), 1:(1,0), 2:(1,1), 3:(0,1)},
...     10
... )
>>> print(motion)
ApproximateMotion of a Graph with vertices [0, 1, 2, 3] and edges [[0, 1], [0, 3], [1, 2], [2, 3]] with starting configuration
{0: [0.0, 0.0], 1: [1.0, 0.0], 2: [1.0, 1.0], 3: [0.0, 1.0]},
10 retraction steps and initial step size 0.1.
>>> F = Framework(graphs.Cycle(4), {0:(0,0), 1:(1,0), 2:(1,1), 3:(0,1)})
>>> motion = ApproximateMotion(F, 10)
>>> print(motion)
ApproximateMotion of a Graph with vertices [0, 1, 2, 3] and edges [[0, 1], [0, 3], [1, 2], [2, 3]] with starting configuration
{0: [0.0, 0.0], 1: [1.0, 0.0], 2: [1.0, 1.0], 3: [0.0, 1.0]},
10 retraction steps and initial step size 0.1.
__repr__()[source]

Return a representation of the approximate motion.

Return type:

str

__str__()[source]

Return the string representation.

Return type:

str

animate(**kwargs)[source]

Animate the approximate motion.

See the parent method animate() for the list of possible keywords.

Return type:

Any

property chosen_flex: int

Return the chosen flex of the motion.

property edge_lengths: dict[set[Hashable] | tuple[Hashable, Hashable] | list[Hashable], int | float | str]

Return a copy of the edge lengths.

fix_pair_of_vertices(fixed_pair, fixed_direction=None)[source]

Pin fixed_pair to the vector given by fixed_direction.

The default value for fixed_direction is the first standard unit vector [1,0,...,0].

Parameters:
Return type:

None

fix_vertex(vertex)[source]

Pin vertex to the origin.

Parameters:

vertex (Hashable) – The vertex that is pinned to the origin.

Return type:

None

property fixed_direction: Sequence[int | float | str]

Return the vector to which fixed_pair is fixed in the motion.

property fixed_pair: tuple[Hashable, Hashable] | list[Hashable]

Return the fixed pair of the motion.

classmethod from_graph(graph, realization, steps, step_size=0.1, chosen_flex=0, tolerance=1e-05, fixed_pair=None, fixed_direction=None, pinned_vertex=None)[source]

Create an instance from a graph with a realization.

Return type:

Motion

Parameters:
property motion_samples: list[dict[Hashable, Sequence[int | float | str]]]

Return a copy of the motion samples.

property pinned_vertex: Hashable

Return the pinned vertex of the motion.

property starting_realization: dict[Hashable, Sequence[int | float | str]]

Return the starting realization of the motion.

property step_size: float

Return the step size of the motion.

property steps: int

Return the number of steps.

property tolerance: float

Return the tolerance for Newton’s method.

class pyrigi.motion.Motion(graph, dim)[source]

Bases: object

An abstract class representing a continuous flex of a framework.

Parameters:
__repr__()[source]

Return a representation of the motion.

Return type:

str

__str__()[source]

Return the string representation

Return type:

str

animate(realizations, plot_style, animation_format='svg', **kwargs)[source]

Animate the continuous motion.

The motion can be animated only if its dimension is less than 3. This method calls animate2D() or animate3D(). For various formatting options, see PlotStyle.

Parameters:
  • realizations (Sequence[dict[Hashable, Sequence[int | float | str]]]) – A sequence of realizations of the underlying graph describing the motion.

  • plot_style (PlotStyle) – An instance of the PlotStyle class that defines the visual style for plotting, see PlotStyle for more details.

  • animation_format (Literal['svg', 'matplotlib']) – In dimension two, the animation_format can be set to determine, whether the output is in the .svg format or in the matplotlib format. The “svg” method is documented here: animate2D_svg(). The method for “matplotlib” is documented here: animate2D_plt().

Return type:

Any

animate2D_plt(realizations, plot_style, edge_colors_custom=None, duration=8, **kwargs)[source]

Animate the continuous motion in 2D.

See PlotStyle2D for a list of possible visualization keywords. Not necessarily all of them apply (e.g. keywords related to infinitesimal flexes are ignored). If the dimension of the motion is 1, then we embed it in \(\RR^2\).

Parameters:
Return type:

Any

animate2D_svg(realizations, plot_style, filename=None, duration=8, **kwargs)[source]

Animate the motion as a .svg file.

See PlotStyle2D for a list of possible visualization keywords. Not necessarily all of them apply (e.g. keywords related to infinitesimal flexes are ignored).

Parameters:
  • plot_style (PlotStyle) – An instance of the PlotStyle class that defines the visual style for plotting, see PlotStyle for more details.

  • filename (str) – A name used to store the svg. If None, the svg is not saved.

  • duration (float) – The duration of one period of the animation in seconds.

  • realizations (Sequence[dict[Hashable, Sequence[int | float | str]]])

Return type:

Any

Notes

Picking the value plot_style.vertex_size*5/plot_style.edge_width for the markerWidth and markerHeight ensures that the plot_style.edge_width does not rescale the vertex size (seems to be an odd, inherent behavior of .svg).

animate3D(realizations, plot_style, edge_colors_custom=None, duration=8, **kwargs)[source]

Animate the continuous motion in 3D.

See PlotStyle3D for a list of possible visualization keywords. Not necessarily all of them apply (e.g. keywords related to infinitesimal flexes are ignored).

Parameters:
Return type:

Any

property dim: int

Return the dimension of the motion.

property graph: Graph

Return a copy of the underlying graph.

class pyrigi.motion.ParametricMotion(graph, motion, interval)[source]

Bases: Motion

Class representing a parametric motion.

Definitions

Continuous flex (motion)

Parameters:

Examples

>>> from pyrigi import ParametricMotion
>>> import sympy as sp
>>> from pyrigi import graphDB as graphs
>>> motion = ParametricMotion(
...     graphs.Cycle(4),
...     {
...         0: ("0", "0"),
...         1: ("1", "0"),
...         2: ("4 * (t**2 - 2) / (t**2 + 4)", "12 * t / (t**2 + 4)"),
...         3: (
...             "(t**4 - 13 * t**2 + 4) / (t**4 + 5 * t**2 + 4)",
...             "6 * (t**3 - 2 * t) / (t**4 + 5 * t**2 + 4)",
...         ),
...     },
...     [-sp.oo, sp.oo],
... )
>>> print(motion)
ParametricMotion of a Graph with vertices [0, 1, 2, 3] and edges [[0, 1], [0, 3], [1, 2], [2, 3]] with motion defined for every vertex:
0: Matrix([[0], [0]])
1: Matrix([[1], [0]])
2: Matrix([[(4*t**2 - 8)/(t**2 + 4)], [12*t/(t**2 + 4)]])
3: Matrix([[(t**4 - 13*t**2 + 4)/(t**4 + 5*t**2 + 4)], [(6*t**3 - 12*t)/(t**4 + 5*t**2 + 4)]])
__repr__()[source]

Return a representation of the parametric motion.

Return type:

str

__str__()[source]

Return the string representation.

Return type:

str

animate(sampling=50, **kwargs)[source]

Animate the parametric motion.

See the parent method animate() for a list of possible keywords.

Parameters:

sampling (int) – The number of discrete points or frames used to approximate the motion in the animation. A higher value results in a smoother and more accurate representation of the motion, while a lower value can speed up rendering but may lead to a less precise or jerky animation. This parameter controls the resolution of the animation movement by setting the density of sampled data points between keyframes or time steps.

Return type:

Any

interval()[source]

Return the underlying interval.

Return type:

list[int | float | str]

parametrization(as_points=False)[source]

Return the parametrization.

Return type:

dict[Hashable, Sequence[int | float | str]]

Parameters:

as_points (bool)

realization(value, numerical=False)[source]

Return a specific realization for the given value of the parameter.

Parameters:
  • value (int | float | str) – The parameter of the deformation path is substituted by value.

  • numerical (bool) – Boolean determining whether the sympy expressions are supposed to be evaluated to numerical (True) or not (False).

Return type:

dict[slice(typing.Hashable, collections.abc.Sequence[int | float | str], None)]