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
- 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 thei
-th flex from the list ofFramework.inf_flexes()
fori=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 thex
-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 offixed_pair
.pinned_vertex (
Hashable
) – If the keywordfixed_pair
is not set, we can use the keywordpinned_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.
- animate(**kwargs)[source]¶
Animate the approximate motion.
See the parent method
animate()
for the list of possible keywords.- Return type:
- 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 byfixed_direction
.The default value for
fixed_direction
is the first standard unit vector[1,0,...,0]
.
- 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.
- property motion_samples: list[dict[Hashable, Sequence[int | float | str]]]¶
Return a copy of the motion samples.
- class pyrigi.motion.Motion(graph, dim)[source]¶
Bases:
object
An abstract class representing a continuous flex of a framework.
- 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()
oranimate3D()
. For various formatting options, seePlotStyle
.- 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 thePlotStyle
class that defines the visual style for plotting, seePlotStyle
for more details.animation_format (
Literal
['svg'
,'matplotlib'
]) – In dimension two, theanimation_format
can be set to determine, whether the output is in the.svg
format or in thematplotlib
format. The “svg” method is documented here:animate2D_svg()
. The method for “matplotlib” is documented here:animate2D_plt()
.
- Return type:
- 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:
realizations (
Sequence
[dict
[Hashable
,Sequence
[int
|float
|str
]]]) – A list of realization samples describing the motion.plot_style (
PlotStyle
) – An instance of thePlotStyle
class that defines the visual style for plotting, seePlotStyle
for more details.edge_colors_custom (
Sequence
[Sequence
[set
[Hashable
] |tuple
[Hashable
,Hashable
] |list
[Hashable
]]] |dict
[str
,Sequence
[set
[Hashable
] |tuple
[Hashable
,Hashable
] |list
[Hashable
]]]) – Optional parameter to specify the colors of edges. It can be aSequence[Sequence[Edge]]
to define groups of edges with the same color or adict[str, Sequence[Edge]]
where the keys are color strings and the values are lists of edges. The omitted edges are given the valueplot_style.edge_color
.duration (
float
) – The duration of one period of the animation in seconds.
- Return type:
- 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 thePlotStyle
class that defines the visual style for plotting, seePlotStyle
for more details.filename (
str
) – A name used to store the svg. IfNone
, 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:
Notes
Picking the value
plot_style.vertex_size*5/plot_style.edge_width
for themarkerWidth
andmarkerHeight
ensures that theplot_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:
realizations (
Sequence
[dict
[Hashable
,Sequence
[int
|float
|str
]]]) – A list of realization samples describing the motion.plot_style (
PlotStyle
) – An instance of thePlotStyle
class that defines the visual style for plotting, seePlotStyle
for more details.edge_colors_custom (
Sequence
[Sequence
[set
[Hashable
] |tuple
[Hashable
,Hashable
] |list
[Hashable
]]] |dict
[str
,Sequence
[set
[Hashable
] |tuple
[Hashable
,Hashable
] |list
[Hashable
]]]) – Optional parameter to specify the colors of edges. It can be aSequence[Sequence[Edge]]
to define groups of edges with the same color or adict[str, Sequence[Edge]]
where the keys are color strings and the values are lists of edges. The omitted edges are given the valueplot_style.edge_color
.duration (
float
) – The duration of one period of the animation in seconds.
- Return type:
- class pyrigi.motion.ParametricMotion(graph, motion, interval)[source]¶
Bases:
Motion
Class representing a parametric motion.
Definitions
- 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)]])
- 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: