<jupyter_start><jupyter_text>Introduction In this notebook you will learn how to make a simple 3D visualization of the motion of the human using [pydy-viz](https://github.com/pydy/pydy-viz).  Setup Display the problem diagram for reference:<jupyter_code>from __future__ import print_function, division
from IPython.display import Image
Image('figures/human_balance_diagram.png')
from solution.simulation import *<jupyter_output><empty_output><jupyter_text>We import the shapes we are going to use in our visualization.<jupyter_code>from pydy.viz.shapes import Cylinder, Sphere
import pydy.viz
pydy.viz.shapes.__all__<jupyter_output><empty_output><jupyter_text>Import other methods from the package!<jupyter_code>from pydy.viz.visualization_frame import VisualizationFrame
from pydy.viz.scene import Scene<jupyter_output><empty_output><jupyter_text>Visualization First we need to create shapes to associate with rigid body. We will start by creating a sphere to represent each joint.<jupyter_code>Sphere?
ankle_shape = Sphere(color='black', radius=0.1)
knee_shape = Sphere(color='black', radius=0.1)
hip_shape = Sphere(color='black', radius=0.1)
head_shape = Sphere(color='black', radius=0.125)<jupyter_output><empty_output><jupyter_text>Now create a visualization frame for each of the shapes. A `VisualizationFrame` object essentially attaches a shape to a reference frame and a point. Since it doesn't matter if the spheres rotate, we can simply attach them to the inertial reference frame.<jupyter_code>VisualizationFrame?
ankle_viz_frame = VisualizationFrame(inertial_frame, ankle, ankle_shape)
knee_viz_frame = VisualizationFrame(inertial_frame, knee, knee_shape)
hip_viz_frame = VisualizationFrame(inertial_frame, hip, hip_shape)<jupyter_output><empty_output><jupyter_text>Here create a point for a "Head" and teh `VisualizationFrame`.<jupyter_code>head = Point('N')  # N for Noggin
head.set_pos(hip, 2 * torso_com_length * torso_frame.y)
head_viz_frame = VisualizationFrame(inertial_frame, head, head_shape)<jupyter_output><empty_output><jupyter_text>We will also need some points for the geometric center of the lower leg, upper leg, and torso. If we attache a `Cylinder` shape to those bodies, the `Cylinder` is defined with it's long axis along the Y direction of the attached reference frame and the geometric center is the local origin.<jupyter_code>lower_leg_center = Point('l_c')
upper_leg_center = Point('u_c')
torso_center = Point('t_c')
lower_leg_center.set_pos(ankle, lower_leg_length / 2 * lower_leg_frame.y)
upper_leg_center.set_pos(knee, upper_leg_length / 2 * upper_leg_frame.y)
torso_center.set_pos(hip, torso_com_length * torso_frame.y)<jupyter_output><empty_output><jupyter_text>It will be helpful to have easy access to the constants to specify the cylinder lengths.<jupyter_code>constants_dict = dict(zip(constants, numerical_constants))
constants_dict<jupyter_output><empty_output><jupyter_text>Now create some cylinders to attach to the three rigid bodies.<jupyter_code>Cylinder?
lower_leg_shape = Cylinder(radius=0.08, length=constants_dict[lower_leg_length], color='blue')

lower_leg_viz_frame = VisualizationFrame('Lower Leg', lower_leg_frame, lower_leg_center, lower_leg_shape)
upper_leg_shape = Cylinder(radius=0.08, length=constants_dict[upper_leg_length], color='green')

upper_leg_viz_frame = VisualizationFrame('Upper Leg', upper_leg_frame, upper_leg_center, upper_leg_shape)
torso_shape = Cylinder(radius=0.08, length=2 * constants_dict[torso_com_length], color='red')

torso_viz_frame = VisualizationFrame('Torso', torso_frame, torso_center, torso_shape)<jupyter_output><empty_output><jupyter_text>Now we create a scene whose base frame is the system's inertial frame and whose origin is the ankle point.<jupyter_code>Scene?
scene = Scene(inertial_frame, ankle)<jupyter_output><empty_output><jupyter_text>Now we append the frames we wish to visualize in the scene object, as a list.<jupyter_code>scene.visualization_frames = [ankle_viz_frame,
                              knee_viz_frame,
                              hip_viz_frame,
                              head_viz_frame,
                              lower_leg_viz_frame,
                              upper_leg_viz_frame,
                              torso_viz_frame]<jupyter_output><empty_output><jupyter_text>We provide the scene with the list of symbolic states, the list of constants, as well as the numerical values of each.<jupyter_code>scene.states_symbols = coordinates + speeds
scene.constants = constants_dict
scene.states_trajectories = y<jupyter_output><empty_output><jupyter_text>Finally, we can display the visualization of the free motion of the system in the cell with the following method:<jupyter_code>scene.display_ipython()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0795978215333054, 'fraction_numerical': 0.005027230833682447, 'mean_word_length': 6.105654761904762, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '294675', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1496, 'n_words': 395, 'path': 'notebooks/n08_visualization.ipynb', 'repo_name': 'pydy/pydy-tutorial-human-standing', 'size': '4774'}