.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/10_animation/viz_robot_arm_animation.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_10_animation_viz_robot_arm_animation.py: =================== Arm Robot Animation =================== Tutorial on making a robot arm animation in FURY. .. GENERATED FROM PYTHON SOURCE LINES 8-22 .. code-block:: Python 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-42 .. code-block:: Python 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 43-44 Setting the center of both shafts to the beginning. .. GENERATED FROM PYTHON SOURCE LINES 44-47 .. code-block:: Python 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 48-49 Creating a timeline .. GENERATED FROM PYTHON SOURCE LINES 49-51 .. code-block:: Python timeline = Timeline(playback_panel=True) .. GENERATED FROM PYTHON SOURCE LINES 52-53 Creating animations .. GENERATED FROM PYTHON SOURCE LINES 53-58 .. code-block:: Python 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 59-60 Adding other Animations in hierarchical order .. GENERATED FROM PYTHON SOURCE LINES 60-64 .. code-block:: Python main_arm_animation.add_child_animation(child_arm_animation) child_arm_animation.add_child_animation(drill_animation) .. GENERATED FROM PYTHON SOURCE LINES 65-66 Creating Arm joints time dependent animation functions. .. GENERATED FROM PYTHON SOURCE LINES 66-80 .. code-block:: Python 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 81-83 Setting timelines (joints) relative position 1- Placing the main arm on the cube static base. .. GENERATED FROM PYTHON SOURCE LINES 83-85 .. code-block:: Python main_arm_animation.set_position(0, np.array([0, 1.3, 0])) .. GENERATED FROM PYTHON SOURCE LINES 86-88 2- Translating the timeline containing the sub arm to the end of the first arm. .. GENERATED FROM PYTHON SOURCE LINES 88-90 .. code-block:: Python child_arm_animation.set_position(0, np.array([12, 0, 0])) .. GENERATED FROM PYTHON SOURCE LINES 91-92 3- Translating the timeline containing the drill to the end of the sub arm. .. GENERATED FROM PYTHON SOURCE LINES 92-94 .. code-block:: Python drill_animation.set_position(0, np.array([8, 0, 0])) .. GENERATED FROM PYTHON SOURCE LINES 95-96 Setting rotation time-based evaluators .. GENERATED FROM PYTHON SOURCE LINES 96-100 .. code-block:: Python 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 101-102 Setting camera position to observe the robot arm. .. GENERATED FROM PYTHON SOURCE LINES 102-104 .. code-block:: Python scene.camera().SetPosition(0, 0, 90) .. GENERATED FROM PYTHON SOURCE LINES 105-106 Adding the base actor to the scene .. GENERATED FROM PYTHON SOURCE LINES 106-108 .. code-block:: Python scene.add(base) .. GENERATED FROM PYTHON SOURCE LINES 109-110 Adding the main parent animation to the Timeline. .. GENERATED FROM PYTHON SOURCE LINES 110-112 .. code-block:: Python timeline.add_animation(main_arm_animation) .. GENERATED FROM PYTHON SOURCE LINES 113-114 Now we add the timeline to the ShowManager .. GENERATED FROM PYTHON SOURCE LINES 114-122 .. code-block:: Python 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_examples/10_animation/images/sphx_glr_viz_robot_arm_animation_001.png :alt: viz robot arm animation :srcset: /auto_examples/10_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.107 seconds) .. _sphx_glr_download_auto_examples_10_animation_viz_robot_arm_animation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: viz_robot_arm_animation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: viz_robot_arm_animation.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_