viz¶
Introduction¶
The viz package in pydy is designed to facilitate browser based animations for PyDy framework.
Typically the plugin is used to generate animations for multibody systems. The systems are defined with sympy.physics.mechanics, solved numerically with the codegen package and scipy, and then visualized with this package. But the required data for the animations can theorectically be generated by other methods and passed into a Scene object.
The frontend is based on three.js, a popular interface to the WebGraphics Library (WegGL). The package provides a Python wrapper for some basic functionality for Three.js i.e Geometries, Lights, Cameras etc.
PyDy Visualizer¶
The PyDy Visualizer is a browser based GUI built to render the visualizations
generated by pydy.viz
. This document provides an overview of PyDy
Visualizer. It describes the various features of the visualizer and provides
instructions to use it.
The visualizer can be embedded inside an IPython notebook or displayed standalone in the browser. Inside the IPython notebook, it also provides additional functionality to interactively modify the simulation parameters. The EoMs can be re-integrated using a click of a button from GUI, and can be viewed inside the same GUI in real time.
Here is a screenshot of the visualizer, when it is called from outside the notebook, i.e. from the Python interpreter:
GUI Elements¶
- (1) Play, Pause, and Stop Buttons
Allows you to start, pause, and stop the animation.
- (2) Play Looped
When checked the animation is run in a loop.
- (3) Time Slider
This is used to traverse to the particular frame in animation, by sliding the slider forward and backward. When the animation is running it will continue from the point where the slider is slid to.
- (4) Canvas
Where the animation is rendered. It supports mouse controls:
Mouse wheel to zoom in, zoom out.
Click and drag to rotate camera.
- (5) Show Model
Shows the current JSON which is being rendered in visualizer. It can be copied from the text-box, as well as downloaded. On clicking “Show Model”, following dialog is created:
- (6) Edit Objects
On clicking this button, a dropdown opens up, showing the list of shapes which are rendered in the animation:
On clicking any object from the dropdown, a dialog box opens up, containing the existing info on that object. The info can be edited. After editing click the “Apply” button for the changes to be reflected in the canvas (4).
- (7) Close Dialog
Closes/hides the “edit objects” dialog.
Additional options in IPython notebooks:
In IPython notebooks, apart from the features mentioned above, there is an additional feature to edit simulation parameters, from the GUI itself. This is how the Visualizer looks, when called from inside an IPython notebook:
Here, one can add custom values in text-boxes(1, 2, 3 etc.) and on clicking “Rerun” (4) the simulations are re-run in the background. On completing, the scene corresponding to the new data is rendered on the Canvas.
API¶
Python¶
- class pydy.viz.camera.OrthoGraphicCamera(*args, **kwargs)[source]¶
Creates a orthographic camera for use in a scene. The camera is inherited from
VisualizationFrame
, and thus behaves similarly. It can be attached to dynamics objects, hence we can get a moving camera. All the transformation matrix generation methods are applicable to aOrthoGraphicCameraCamera
.- __init__(*args, **kwargs)[source]¶
Initialises a OrthoGraphicCameraCamera object. To initialize a OrthoGraphicCameraCamera, one needs to supply a name (optional), a reference frame, a point, field of view (fov) (optional), near plane distance (optional) and far plane distance (optional).
Like
VisualizationFrame
, it can also be initialized using one of these three argument sequences:- Rigidbody
OrthoGraphicCameraCamera(rigid_body)
- ReferenceFrame, Point
OrthoGraphicCameraCamera(ref_frame, point)
- ReferenceFrame, Particle
OrthoGraphicCameraCamera(ref_frame, particle)
Note that you can also supply and optional name as the first positional argument, e.g.:
OrthoGraphicCameraCamera('camera_name', rigid_body)
Additional optional keyword arguments are below:
- Parameters
- nearfloat
The distance of near plane of the OrthoGraphicCameraCamera. All objects closer to this distance are not displayed.
- farint or float
The distance of far plane of the OrthoGraphicCameraCamera. All objects farther than this distance are not displayed.
Examples
>>> from sympy import symbols >>> from sympy.physics.mechanics import (ReferenceFrame, Point, ... RigidBody, Particle, ... inertia) >>> from pydy.viz import OrthoGraphicCameraCamera >>> I = ReferenceFrame('I') >>> O = Point('O')
>>> # initializing with reference frame, point >>> camera1 = OrthoGraphicCameraCamera('frame1', I, O)
>>> # Initializing with a RigidBody >>> Ixx, Iyy, Izz, mass = symbols('Ixx Iyy Izz mass') >>> i = inertia(I, Ixx, Iyy, Izz) >>> rbody = RigidBody('rbody', O, I, mass, (inertia, O)) >>> camera2 = OrthoGraphicCameraCamera('frame2', rbody)
>>> # initializing with Particle, reference_frame >>> Pa = Particle('Pa', O, mass) >>> camera3 = OrthoGraphicCameraCamera('frame3', I, Pa)
- generate_scene_dict(**kwargs)[source]¶
This method generates information for a static visualization in the initial conditions, in the form of dictionary. This contains camera parameters followed by an init_orientation Key.
- Returns
- scene_dictdictionary
A dict with following Keys:
name: name for the camera
near: near value of the camera
far: far value of the camera
init_orientation: Initial orientation of the camera
- class pydy.viz.camera.PerspectiveCamera(*args, **kwargs)[source]¶
Creates a perspective camera for use in a scene. The camera is inherited from
VisualizationFrame
, and thus behaves similarly. It can be attached to dynamics objects, hence we can get a moving camera. All the transformation matrix generation methods are applicable to aPerspectiveCamera
.- __init__(*args, **kwargs)[source]¶
Initialises a PerspectiveCamera object. To initialize a PerspectiveCamera, one needs to supply a name (optional), a reference frame, a point, field of view (fov) (optional), near plane distance (optional) and far plane distance (optional).
Like
VisualizationFrame
, it can also be initialized using one of these three argument sequences:Rigidbody
PerspectiveCamera(rigid_body)
ReferenceFrame, PointPerspectiveCamera(ref_frame, point)
ReferenceFrame, ParticlePerspectiveCamera(ref_frame, particle)
Note that you can also supply and optional name as the first positional argument, e.g.:
``PerspectiveCamera('camera_name', rigid_body)``
Additional optional keyword arguments are below:
- Parameters
- fovfloat, default=45.0
Field Of View, It determines the angle between the top and bottom of the viewable area (in degrees).
- nearfloat
The distance of near plane of the PerspectiveCamera. All objects closer to this distance are not displayed.
- farint or float
The distance of far plane of the PerspectiveCamera. All objects farther than this distance are not displayed.
Examples
>>> from sympy import symbols >>> from sympy.physics.mechanics import (ReferenceFrame, Point, ... RigidBody, Particle, ... inertia) >>> from pydy.viz import PerspectiveCamera >>> I = ReferenceFrame('I') >>> O = Point('O')
>>> # initializing with reference frame, point >>> camera1 = PerspectiveCamera('frame1', I, O)
>>> # Initializing with a RigidBody >>> Ixx, Iyy, Izz, mass = symbols('Ixx Iyy Izz mass') >>> i = inertia(I, Ixx, Iyy, Izz) >>> rbody = RigidBody('rbody', O, I, mass, (inertia, O)) >>> camera2 = PerspectiveCamera('frame2', rbody)
>>> # initializing with Particle, reference_frame >>> Pa = Particle('Pa', O, mass) >>> camera3 = PerspectiveCamera('frame3', I, Pa)
- generate_scene_dict(**kwargs)[source]¶
This method generates information for a static visualization in the initial conditions, in the form of dictionary. This contains camera parameters followed by an init_orientation key.
Before calling this method, all the transformation matrix generation methods should be called, or it will give an error.
- Returns
- A dict with following Keys:
- name: name for the camera
- fov: Field of View value of the camera
- near: near value of the camera
- far: far value of the camera
- init_orientation: Initial orientation of the camera
- class pydy.viz.light.PointLight(*args, **kwargs)[source]¶
Creates a PointLight for the visualization The PointLight is inherited from VisualizationFrame,
It can also be attached to dynamics objects, hence we can get a moving Light. All the transformation matrix generation methods are applicable to a PointLight. Like VisualizationFrame, It can also be initialized using: 1)Rigidbody 2)ReferenceFrame, Point 3)ReferenceFrame, Particle Either one of these must be supplied during initialization
Unlike VisualizationFrame, It doesnt require a Shape argument.
- __init__(*args, **kwargs)[source]¶
Initialises a PointLight object. To initialize a point light, we need to supply a name(optional), a reference frame, and a point.
- Parameters
- namestr, optional
Name assigned to VisualizationFrame, default is unnamed
- reference_frameReferenceFrame
A reference_frame with respect to which all orientations of the shape takes place, during visualizations/animations.
- originPoint
A point with respect to which all the translations of the shape takes place, during visualizations/animations.
- rigidbodyRigidBody
A rigidbody whose reference frame and mass center are to be assigned as reference_frame and origin of the VisualizationFrame.
- particleParticle
A particle whose point is assigned as origin of the VisualizationFrame.
Examples
>>> from pydy.viz import PointLight >>> from sympy.physics.mechanics import ReferenceFrame, Point, RigidBody, Particle, inertia >>> from sympy import symbols >>> I = ReferenceFrame('I') >>> O = Point('O') >>> #initializing with reference frame, point >>> light = PointLight('light', I, O) >>> Ixx, Iyy, Izz, mass = symbols('Ixx Iyy Izz mass') >>> i = inertia(I, Ixx, Iyy, Izz) >>> rbody = RigidBody('rbody', O, I, mass, (inertia, O)) >>> # Initializing with a rigidbody .. >>> light = PointLight('frame2', rbody) >>> Pa = Particle('Pa', O, mass) >>> #initializing with Particle, reference_frame ... >>> light = PointLight('frame3', I, Pa)
- property color¶
Color of Light.
- generate_scene_dict()[source]¶
This method generates information for a static visualization in the initial conditions, in the form of dictionary. This contains light parameters followed by an init_orientation Key.
Before calling this method, all the transformation matrix generation methods should be called, or it will give an error. Returns ======= A dict with following Keys:
name: name for the camera
color: Color of the light
init_orientation: Initial orientation of the light object
- generate_simulation_dict()[source]¶
Generates the simulation information for this Light object. It maps the simulation data information to the scene information via a unique id.
Before calling this method, all the transformation matrix generation methods should be called, or it will give an error.
- Returns
- A dictionary containing list of 4x4 matrices mapped to
- the unique id as the key.
- class pydy.viz.scene.Scene(reference_frame, origin, *visualization_frames, **kwargs)[source]¶
The Scene class generates all of the data required for animating a set of visualization frames.
- __init__(reference_frame, origin, *visualization_frames, **kwargs)[source]¶
Initialize a Scene instance.
- Parameters
- reference_framesympy.physics.mechanics.ReferenceFrame
The base reference frame for the scene. The motion of all of the visualization frames, cameras, and lights will be generated with respect to this reference frame.
- originsympy.physics.mechanics.Point
The base point for the scene. The motion of all of the visualization frames, cameras, and lights will be generated with respect to this point.
- visualization_framesVisualizationFrame
One or more visualization frames which are to be displayed in the scene.
- namestring, optional, default=’unnamed’
Name of Scene object.
- cameraslist of Camera instances, optional
The cameras with which to display the object. The first camera is used to display the scene initially. The default is a single PerspectiveCamera tied to the base reference frame and positioned away from the origin along the reference frame’s z axis.
- lightslist of Light instances, optional
The lights used in the scene. The default is a single Light tied to the base reference frame and positioned away from the origin along the reference frame’s z axis at the same point as the default camera.
- systemSystem, optional, default=None
A PyDy system class which is initiated such that the
integrate()
method will produce valid state trajectories.- timesarray_like, shape(n,), optional, default=None
Monotoncially increaing float values of time that correspond to the state trajectories.
- constantsdictionary, optional, default=None
A dictionary that maps SymPy symbols to floats. This should contain at least all necessary symbols to evaluate the transformation matrices of the visualization frame, cameras, and lights and to evaluate the Shapes’ parameters.
- states_symbolssequence of functions, len(m), optional, default=None
An ordered sequence of the SymPy functions that represent the states. The order must match the order of the
states_trajectories
.- states_trajectoriesarray_like, shape(n, m), optional, default=None
A two dimensional array with numerical values for each state at each point in time during the animation.
Notes
The user is allowed to supply either system or times, constants, states_symbols, and states_trajectories. Providing a System allows for interactively changing the simulation parameters via the Scene GUI in the IPython notebook.
- clear_trajectories()[source]¶
Sets the ‘system’, ‘times’, ‘constants’, ‘states_symbols’, and ‘states_trajectories’ to None.
- create_static_html(overwrite=False, silent=False, prefix=None)[source]¶
Creates a directory named
pydy-visualization
in the current working directory which contains all of the HTML, CSS, Javascript, and json files required to run the vizualization application. To run the application, navigate into thepydy-visualization
directory and start a webserver from that directory, e.g.:$ python -m SimpleHTTPServer
Now, in a WebGL compliant browser, navigate to:
http://127.0.0.1:8000
to view and interact with the visualization.
This method can also be used to output files for embedding the visualizations in static webpages. Simply copy the contents of static directory in the relevant directory for embedding in a static website.
- Parameters
- overwriteboolean, optional, default=False
If True, the directory named
pydy-visualization
in the current working directory will be overwritten.- silentboolean, optional, default=False
If True, no messages will be displayed to STDOUT.
- prefixstring, optional
An optional prefix for the json data files.
- display_ipython()[source]¶
Displays the scene using an IPython widget inside an IPython notebook cell.
Notes
IPython widgets are only supported by IPython versions >= 3.0.0.
- display_jupyter(window_size=(800, 600), axes_arrow_length=None)[source]¶
Returns a PyThreeJS Renderer and AnimationAction for displaying and animating the scene inside a Jupyter notebook.
- Parameters
- window_size2-tuple of integers
2-tuple containing the width and height of the renderer window in pixels.
- axes_arrow_lengthfloat
If a positive value is supplied a red (x), green (y), and blue (z) arrows of the supplied length will be displayed as arrows for the global axes.
- Returns
- vboxwidgets.VBox
A vertical box containing the action (pythreejs.AnimationAction) and renderer (pythreejs.Renderer).
- generate_visualization_json_system(system, **kwargs)[source]¶
Creates the visualization JSON files for the provided system.
- Parameters
- systempydy.system.System
A fully developed PyDy system that is prepared for the
.integrate()
method.- fpsint, optional, default=30
Frames per second at which animation should be displayed. Please not that this should not exceed the hardware limit of the display device to be used. Default is 30fps.
- outfile_prefixstr, optional, default=None
A prefix for the JSON files. The files will be named as outfile_prefix_scene_desc.json and outfile_prefix_simulation_data.json. If not specified a timestamp shall be used as the prefix.
Notes
The optional keyword arguments are the same as those in the
generate_visualization_json
method.
- property name¶
Returns the name of the scene.
- property origin¶
Returns the origin point of the scene.
- property reference_frame¶
Returns the base reference frame of the scene.
- class pydy.viz.server.Server(scene_file, directory='static/', port=8000)[source]¶
- Parameters
- portinteger
Defines the port on which the server will run. If this port is already bind, then it increment 1 until it finds a free port.
- scene_filename of the scene_file generated for visualization
A Valid PyDy generated scene file in ‘directory’ parameter.
- directoryabsolute path of a directory
Absolute path to the directory which contains scene_file with all other static files.
- class pydy.viz.shapes.Box(width, height, depth, **kwargs)[source]¶
Instantiates a box of a given size.
- Parameters
- widthfloat or SymPy expression
Width of the box along the X axis.
- heightfloat or SymPy expression
Height of the box along the Y axis.
- depthfloat or SymPy expression
Depth of the box along the Z axis.
Examples
>>> from pydy.viz.shapes import Box >>> s = Box(10.0, 5.0, 1.0) >>> s.name 'unnamed' >>> s.color 'grey' >>>s.width 5.0 >>>s.height 1.0 >>>s.depth 10.0 >>> s.name = 'my-shape1' >>> s.name 'my-shape1' >>> s.color = 'blue' >>> s.color 'blue'
- class pydy.viz.shapes.Circle(radius=10.0, **kwargs)[source]¶
Instantiates a circle with a given radius.
- Parameters
- radiusfloat or SymPy Expression
The radius of the circle.
Examples
>>> from pydy.viz.shapes import Circle >>> s = Circle(10.0) >>> s.name 'unnamed' >>> s.color 'grey' >>>s.radius 10.0 >>> s.name = 'my-shape1' >>> s.name 'my-shape1' >>> s.color = 'blue' >>> s.color 'blue' >>> s.radius = 12.0 >>> s.radius 12.0 >>> a = Circle(10.0, name='my-shape2', color='red') >>> a.name 'my-shape2' >>> a.color 'red' >>> a.radius 10.0
- class pydy.viz.shapes.Cone(length, radius, **kwargs)[source]¶
Instantiates a cone with given length and base radius.
- Parameters
- lengthfloat or SymPy expression
The length of the cone.
- radiusfloat or SymPy expression
The base radius of the cone.
Examples
>>> from pydy.viz.shapes import Cone >>> s = Cone(10.0, 5.0) >>> s.name 'unnamed' >>> s.color 'grey' >>> s.length 10.0 >>> s.radius 5.0 >>> s.name = 'my-shape1' >>> s.name 'my-shape1' >>> s.color = 'blue' >>> s.color 'blue' >>> s.length = 12.0 >>> s.length 12.0 >>> s.radius = 6.0 >>> s.radius 6.0 >>> a = Cone(10.0, 5.0, name='my-shape2', color='red') >>> a.name 'my-shape2' >>> a.color 'red' >>> a.length 10.0 >>> a.radius 5.0
- class pydy.viz.shapes.Cube(length, **kwargs)[source]¶
Instantiates a cube of a given size.
- Parameters
- lengthfloat or SymPy expression
The length of the cube.
Examples
>>> from pydy.viz.shapes import Cube >>> s = Cube(10.0) >>> s.name 'unnamed' >>> s.color 'grey' >>>s.length 10.0 >>> s.name = 'my-shape1' >>> s.name 'my-shape1' >>> s.color = 'blue' >>> s.color 'blue' >>> s.length = 12.0 >>> s.length 12.0 >>> a = Cube('my-shape2', 'red', length=10) >>> a.name 'my-shape2' >>> a.color 'red' >>> a.length 10.0
- class pydy.viz.shapes.Cylinder(length, radius, **kwargs)[source]¶
Instantiates a cylinder with given length and radius.
- Parameters
- lengthfloat or SymPy expression
Length of the cylinder along its Y axis.
- radiusfloat or SymPy expression
Radius of the cylinder (of the circular cross section normal to the Y axis).
Examples
>>> from pydy.viz.shapes import Cylinder >>> s = Cylinder(10.0, 5.0) >>> s.name 'unnamed' >>> s.color 'grey' >>> s.length 10.0 >>> s.radius 5.0 >>> s.name = 'my-shape1' >>> s.name 'my-shape1' >>> s.color = 'blue' >>> s.color 'blue' >>> s.length = 12.0 >>> s.length 12.0 >>> s.radius = 6.0 >>> s.radius 6.0 >>> a = Cylinder(10.0, 5.0, name='my-shape2', color='red') >>> a.name 'my-shape2' >>> a.color 'red' >>> a.length 10.0 >>> a.radius 5.0
- class pydy.viz.shapes.Icosahedron(radius=10.0, **kwargs)[source]¶
Instantiates an icosahedron inscribed in a sphere of the given radius.
- Parameters
- radiusfloat or a SymPy expression
Radius of the circum-scribing sphere for Icosahedron
Examples
>>> from pydy.viz.shapes import Icosahedron >>> s = Icosahedron(10) >>> s.name 'unnamed' >>> s.color 'grey' >>>s.radius 10.0 >>>#These can be changed later too .. >>> s.name = 'my-shape1' >>> s.name 'my-shape1' >>> s.color = 'blue' >>> s.color 'blue' >>> s.radius = 12.0 >>> s.radius 12 >>> a = Icosahedron(10.0, name='my-shape2', color='red') >>> a.name 'my-shape2' >>> a.color 'red' >>> a.radius 10.0
- class pydy.viz.shapes.Octahedron(radius=10.0, **kwargs)[source]¶
Instantiaties an Octahedron inscribed in a circle of the given radius.
- Parameters
- radiusfloat or SymPy expression.
The radius of the circum-scribing sphere around the octahedron.
Examples
>>> from pydy.viz.shapes import Octahedron >>> s = Octahedron(10.0) >>> s.name 'unnamed' >>> s.color 'grey' >>>s.radius 10.0 >>> s.name = 'my-shape1' >>> s.name 'my-shape1' >>> s.color = 'blue' >>> s.color 'blue' >>> s.radius = 12.0 >>> s.radius 12.0 >>> a = Octahedron(10.0, name='my-shape2', color='red') >>> a.name 'my-shape2' >>> a.color 'red' >>> a.radius 10.0
- class pydy.viz.shapes.Plane(length=10.0, width=5.0, **kwargs)[source]¶
Instantiates a plane with a given length and width.
- Parameters
- lengthfloat or SymPy expression
Length of the plane along the Y axis.
- widthfloat or SymPy expression
Width of the plane along the X axis.
Examples
>>> from pydy.viz.shapes import Plane >>> s = Plane(10.0, 5.0) >>> s.name 'unnamed' >>> s.color 'grey' >>> s.length 10.0 >>> s.width 5.0 >>> s.name = 'my-shape1' >>> s.name 'my-shape1' >>> s.color = 'blue' >>> s.color 'blue' >>> s.length = 12.0 >>> s.length 12.0 >>> s.width = 6.0 >>> s.width 6.0 >>> a = Plane(10.0, 5.0, name='my-shape2', color='red') >>> a.name 'my-shape2' >>> a.color 'red' >>> a.length 10.0 >>> a.width 5.0
- class pydy.viz.shapes.Sphere(radius=10.0, **kwargs)[source]¶
Instantiates a sphere with a given radius.
- Parameters
- radiusfloat or SymPy expression
The radius of the sphere.
Examples
>>> from pydy.viz.shapes import Sphere >>> s = Sphere(10.0) >>> s.name 'unnamed' >>> s.color 'grey' >>>s.radius 10.0 >>> s.name = 'my-shape1' >>> s.name 'my-shape1' >>> s.color = 'blue' >>> s.color 'blue' >>> s.radius = 12.0 >>> s.radius 12.0 >>> a = Sphere(10.0, name='my-shape2', color='red') >>> a.name 'my-shape2' >>> a.color 'red' >>> a.radius 10.0
- class pydy.viz.shapes.Tetrahedron(radius=10.0, **kwargs)[source]¶
Instantiates a Tetrahedron inscribed in a given radius circle.
- Parameters
- radiusfloat or SymPy expression
The radius of the circum-scribing sphere of around the tetrahedron.
Examples
>>> from pydy.viz.shapes import Tetrahedron >>> s = Tetrahedron(10.0) >>> s.name 'unnamed' >>> s.color 'grey' >>>s.radius 10.0 >>> s.name = 'my-shape1' >>> s.name 'my-shape1' >>> s.color = 'blue' >>> s.color 'blue' >>> s.radius = 12.0 >>> s.radius 12.0 >>> a = Tetrahedron(10.0, name='my-shape2', color='red') >>> a.name 'my-shape2' >>> a.color 'red' >>> a.radius 10.0
- class pydy.viz.shapes.Torus(radius, tube_radius, **kwargs)[source]¶
Instantiates a torus with a given radius and section radius.
- Parameters
- radiusfloat or SymPy expression
The radius of the torus.
- tube_radiusfloat or SymPy expression
The radius of the torus tube.
Examples
>>> from pydy.viz.shapes import Torus >>> s = Torus(10.0, 5.0) >>> s.name 'unnamed' >>> s.color 'grey' >>> s.radius 10.0 >>> s.tube_radius 5.0 >>> s.name = 'my-shape1' >>> s.name 'my-shape1' >>> s.color = 'blue' >>> s.color 'blue' >>> s.radius = 12.0 >>> s.radius 12.0 >>> s.tube_radius = 6.0 >>> s.tube_radius 6.0 >>> a = Torus(10.0, 5.0, name='my-shape2', color='red') >>> a.name 'my-shape2' >>> a.color 'red' >>> a.radius 10.0 >>> a.tube_radius 5.0
- class pydy.viz.shapes.TorusKnot(radius, tube_radius, **kwargs)[source]¶
Instantiates a torus knot with given radius and section radius.
- Parameters
- radiusfloat or SymPy expression
The radius of the torus knot.
- tube_radiusfloat or SymPy expression
The radius of the torus knot tube.
Examples
>>> from pydy.viz.shapes import TorusKnot >>> s = TorusKnot(10.0, 5.0) >>> s.name 'unnamed' >>> s.color 'grey' >>> s.radius 10.0 >>> s.tube_radius 5.0 >>> s.name = 'my-shape1' >>> s.name 'my-shape1' >>> s.color = 'blue' >>> s.color 'blue' >>> s.radius = 12.0 >>> s.radius 12.0 >>> s.tube_radius = 6.0 >>> s.tube_radius 6.0 >>> a = TorusKnot(10.0, 5.0, name='my-shape2', color='red') >>> a.name 'my-shape2' >>> a.color 'red' >>> a.radius 10.0 >>> a.tube_radius 5.0
- class pydy.viz.shapes.Tube(radius, points, **kwargs)[source]¶
Instantiates a tube that sweeps along a path.
- Parameters
- radiusfloat or SymPy expression
The radius of the tube.
- pointsarray_like, shape(n, 3)
An array of n (x, y, z) coordinates representing points that the tube’s center line should follow.
Examples
>>> from pydy.viz.shapes import Tube >>> points = [[1.0, 2.0, 1.0], [2.0, 1.0, 1.0], [2.0, 3.0, 4.0]] >>> s = Tube(10.0, points) >>> s.name 'unnamed' >>> s.color 'grey' >>> s.points [[1.0, 2.0, 1.0], [2.0, 1.0, 1.0], [2.0, 3.0, 4.0]] >>> s.name = 'my-shape1' >>> s.name 'my-shape1' >>> s.color = 'blue' >>> s.color 'blue' >>> s.radius = 14.0 >>> s.radius 14.0 >>> s.points = [[2.0, 1.0, 4.0], [1.0, 2.0, 4.0], ... [2.0, 3.0, 1.0], [1.0, 1.0, 3.0]] >>> s.points [[2.0, 1.0, 4.0], [1.0, 2.0, 4.0], [2.0, 3.0, 1.0], [1.0, 1.0, 3.0]] >>> a = Tube(12.0, points, name='my-shape2', color='red') >>> a.name 'my-shape2' >>> a.color 'red' >>> a.radius 12.0 >>> a.points [[1.0, 2.0, 1.0], [2.0, 1.0, 1.0], [2.0, 3.0, 4.0]]
- class pydy.viz.visualization_frame.VisualizationFrame(*args)[source]¶
A VisualizationFrame represents an object that you want to visualize. It allows you to easily associate a reference frame and a point with a shape.
A VisualizationFrame can be attached to only one Shape Object. It can be nested, i.e we can add/remove multiple visualization frames to one visualization frame. On adding the parent frame to the Scene object, all the children of the parent visualization frame are also added, and hence can be visualized and animated.
A VisualizationFrame needs to have a ReferenceFrame, and a Point for it to form transformation matrices for visualization and animations.
The ReferenceFrame and Point are required to be provided during initialization. They can be supplied in the form of any one of these:
1)reference_frame, point argument. 2)a RigidBody argument 3)reference_frame, particle argument.
In addition to these arguments, A shape argument is also required.
- __init__(*args)[source]¶
To initialize a visualization frame a ReferenceFrame, Point, and Shape are required. These ReferenceFrame and Point can be passed provided in three ways:
RigidBody: the RigidBody’s frame and mass center are used.
ReferenceFrame and a Particle: The Particle’s Point is used.
ReferenceFrame and a Point
- Parameters
- namestr, optional
Name assigned to VisualizationFrame, default is unnamed
- reference_frameReferenceFrame
A reference_frame with respect to which all orientations of the shape takes place, during visualizations/animations.
- originPoint
A point with respect to which all the translations of the shape takes place, during visualizations/animations.
- rigidbodyRigidBody
A rigidbody whose reference frame and mass center are to be assigned as reference_frame and origin of the VisualizationFrame.
- particleParticle
A particle whose point is assigned as origin of the VisualizationFrame.
- shapeShape
A shape to be attached to the VisualizationFrame
Examples
>>> from pydy.viz import VisualizationFrame, Sphere >>> from sympy.physics.mechanics import ReferenceFrame, Point, RigidBody, Particle, inertia >>> from sympy import symbols >>> I = ReferenceFrame('I') >>> O = Point('O') >>> shape = Sphere(5) >>> #initializing with reference frame, point >>> frame1 = VisualizationFrame('frame1', I, O, shape) >>> Ixx, Iyy, Izz, mass = symbols('Ixx Iyy Izz mass') >>> i = inertia(I, Ixx, Iyy, Izz) >>> rbody = RigidBody('rbody', O, I, mass, (inertia, O)) >>> # Initializing with a rigidbody .. >>> frame2 = VisualizationFrame('frame2', rbody, shape) >>> Pa = Particle('Pa', O, mass) >>> #initializing with Particle, reference_frame ... >>> frame3 = VisualizationFrame('frame3', I, Pa, shape)
- evaluate_transformation_matrix(dynamic_values, constant_values)[source]¶
Returns the numerical transformation matrices for each time step.
- Parameters
- dynamic_valuesarray_like, shape(m,) or shape(n, m)
The m state values for each n time step.
- constant_valuesarray_like, shape(p,)
The p constant parameter values of the system.
- Returns
- transform_matrixnumpy.array, shape(n, 16)
A 4 x 4 transformation matrix for each time step.
- generate_numeric_transform_function(dynamic_variables, constant_variables)[source]¶
Returns a function which can compute the numerical values of the transformation matrix given the numerical dynamic variables (i.e. functions of time or states) and the numerical system constants.
- Parameters
- dynamic_variableslist of sympy.Functions(time)
All of the dynamic symbols used in defining the orientation and position of this visualization frame.
- constant_variableslist of sympy.Symbols
All of the constants used in defining the orientation and position of this visualization frame.
- Returns
- numeric_transformlist of functions
A list of functions which return the numerical transformation for each element in the transformation matrix.
- generate_scene_dict(constant_map={})[source]¶
This method generates information for a static visualization in the initial conditions, in the form of dictionary. This contains shape information from Shape.generate_dict() followed by an init_orientation Key.
Before calling this method, all the transformation matrix generation methods should be called, or it will give an error.
- Parameters
- constant_mapdictionary
Constant map is required when Shape contains sympy expressions.This dictionary maps sympy expressions/symbols to numerical values(floats)
- Returns
- A dictionary built with a call to Shape.generate_dict.
- Additional keys included in the dict are following:
- init_orientation: Specifies the initial orientation
of the VisualizationFrame.
- reference_frame_name: Name(str) of the reference_frame
attached to this VisualizationFrame.
- simulation_id: an arbitrary integer to map scene description
with the simulation data.
- generate_simulation_dict()[source]¶
Generates the simulation information for this visualization frame. It maps the simulation data information to the scene information via a unique id.
Before calling this method, all the transformation matrix generation methods should be called, or it will give an error.
- Returns
- A dictionary containing list of 4x4 matrices mapped to
- the unique id as the key.
- generate_transformation_matrix(reference_frame, point)[source]¶
Generates a symbolic transformation matrix, with respect to the provided reference frame and point.
- Parameters
- reference_frameReferenceFrame
A reference_frame with respect to which transformation matrix is generated.
- pointPoint
A point with respect to which transformation matrix is generated.
- Returns
- A 4 x 4 SymPy matrix, containing symbolic expressions describing the
- transformation as a function of time.
- property name¶
Name of the VisualizationFrame.
- property origin¶
Origin of the VisualizationFrame, with respect to which all translational transformations take place.
- property reference_frame¶
reference_frame of the VisualizationFrame, with respect to which all rotational/orientational transformations take place.
- property shape¶
shape in the VisualizationFrame. A shape attached to the visualization frame. NOTE: Only one shape can be attached to a visualization frame.