.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_tutorials/05_animation/viz_robot_arm_animation.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_tutorials_05_animation_viz_robot_arm_animation.py: =================== Arm Robot Animation =================== Tutorial on making a robot arm animation in FURY. .. GENERATED FROM PYTHON SOURCE LINES 9-22 .. code-block:: default import numpy as np from fury import actor, window from fury.animation import Animation, Timeline from fury.utils import set_actor_origin scene = window.Scene() showm = window.ShowManager(scene, size=(900, 768), reset_camera=False, order_transparent=True) showm.initialize() .. GENERATED FROM PYTHON SOURCE LINES 23-24 Creating robot arm components .. GENERATED FROM PYTHON SOURCE LINES 24-39 .. code-block:: default base = actor.cylinder(np.array([[0, 0, 0]]), np.array([[0, 1, 0]]), colors=(0, 1, 0), radius=1) main_arm = actor.box(np.array([[0, 0, 0]]), colors=(1, 0.5, 0), scales=(12, 1, 1)) sub_arm = actor.box(np.array([[0, 0, 0]]), colors=(0, 0.5, 0.8), scales=(8, 0.7, 0.7)) joint_1 = actor.sphere(np.array([[0, 0, 0]]), colors=np.array([1, 0, 1]), radii=1.2) joint_2 = actor.sphere(np.array([[0, 0, 0]]), colors=np.array([1, 0, 1])) end = actor.cone(np.array([[0, 0, 0]]), np.array([[1, 0, 0]]), np.array([[1, 0, 0]]), heights=2.2, resolution=6) .. GENERATED FROM PYTHON SOURCE LINES 40-41 Setting the center of both shafts to the beginning. .. GENERATED FROM PYTHON SOURCE LINES 41-44 .. code-block:: default set_actor_origin(main_arm, np.array([-6, 0, 0])) set_actor_origin(sub_arm, np.array([-4, 0, 0])) .. GENERATED FROM PYTHON SOURCE LINES 45-46 Creating a timeline .. GENERATED FROM PYTHON SOURCE LINES 46-48 .. code-block:: default timeline = Timeline(playback_panel=True) .. GENERATED FROM PYTHON SOURCE LINES 49-50 Creating animations .. GENERATED FROM PYTHON SOURCE LINES 50-55 .. code-block:: default main_arm_animation = Animation([main_arm, joint_1], length=2 * np.pi) child_arm_animation = Animation([sub_arm, joint_2]) drill_animation = Animation(end) .. GENERATED FROM PYTHON SOURCE LINES 56-57 Adding other Animations in hierarchical order .. GENERATED FROM PYTHON SOURCE LINES 57-61 .. code-block:: default main_arm_animation.add_child_animation(child_arm_animation) child_arm_animation.add_child_animation(drill_animation) .. GENERATED FROM PYTHON SOURCE LINES 62-63 Creating Arm joints time dependent animation functions. .. GENERATED FROM PYTHON SOURCE LINES 63-76 .. code-block:: default def rot_main_arm(t): return np.array([np.sin(t / 2) * 180, np.cos(t / 2) * 180, 0]) def rot_sub_arm(t): return np.array([np.sin(t) * 180, np.cos(t) * 70, np.cos(t) * 40]) def rot_drill(t): return np.array([t * 1000, 0, 0]) .. GENERATED FROM PYTHON SOURCE LINES 77-79 Setting timelines (joints) relative position 1- Placing the main arm on the cube static base. .. GENERATED FROM PYTHON SOURCE LINES 79-81 .. code-block:: default main_arm_animation.set_position(0, np.array([0, 1.3, 0])) .. GENERATED FROM PYTHON SOURCE LINES 82-84 2- Translating the timeline containing the sub arm to the end of the first arm. .. GENERATED FROM PYTHON SOURCE LINES 84-86 .. code-block:: default child_arm_animation.set_position(0, np.array([12, 0, 0])) .. GENERATED FROM PYTHON SOURCE LINES 87-88 3- Translating the timeline containing the drill to the end of the sub arm. .. GENERATED FROM PYTHON SOURCE LINES 88-90 .. code-block:: default drill_animation.set_position(0, np.array([8, 0, 0])) .. GENERATED FROM PYTHON SOURCE LINES 91-92 Setting rotation time-based evaluators .. GENERATED FROM PYTHON SOURCE LINES 92-96 .. code-block:: default main_arm_animation.set_rotation_interpolator(rot_main_arm, is_evaluator=True) child_arm_animation.set_rotation_interpolator(rot_sub_arm, is_evaluator=True) drill_animation.set_rotation_interpolator(rot_drill, is_evaluator=True) .. GENERATED FROM PYTHON SOURCE LINES 97-98 Setting camera position to observe the robot arm. .. GENERATED FROM PYTHON SOURCE LINES 98-100 .. code-block:: default scene.camera().SetPosition(0, 0, 90) .. GENERATED FROM PYTHON SOURCE LINES 101-102 Adding the base actor to the scene .. GENERATED FROM PYTHON SOURCE LINES 102-104 .. code-block:: default scene.add(base) .. GENERATED FROM PYTHON SOURCE LINES 105-106 Adding the main parent animation to the Timeline. .. GENERATED FROM PYTHON SOURCE LINES 106-108 .. code-block:: default timeline.add_animation(main_arm_animation) .. GENERATED FROM PYTHON SOURCE LINES 109-110 Now we add the timeline to the ShowManager .. GENERATED FROM PYTHON SOURCE LINES 110-119 .. code-block:: default showm.add_animation(timeline) interactive = False if interactive: showm.start() window.record(scene, out_path='viz_robot_arm.png', size=(900, 768)) .. image-sg:: /auto_tutorials/05_animation/images/sphx_glr_viz_robot_arm_animation_001.png :alt: viz robot arm animation :srcset: /auto_tutorials/05_animation/images/sphx_glr_viz_robot_arm_animation_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.112 seconds) .. _sphx_glr_download_auto_tutorials_05_animation_viz_robot_arm_animation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: viz_robot_arm_animation.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: viz_robot_arm_animation.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_