.. 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-23 .. 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 24-25 Creating robot arm components .. GENERATED FROM PYTHON SOURCE LINES 25-43 .. 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 44-45 Setting the center of both shafts to the beginning. .. GENERATED FROM PYTHON SOURCE LINES 45-48 .. 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 49-50 Creating a timeline .. GENERATED FROM PYTHON SOURCE LINES 50-52 .. code-block:: Python timeline = Timeline(playback_panel=True) .. GENERATED FROM PYTHON SOURCE LINES 53-54 Creating animations .. GENERATED FROM PYTHON SOURCE LINES 54-59 .. 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 60-61 Adding other Animations in hierarchical order .. GENERATED FROM PYTHON SOURCE LINES 61-65 .. 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 66-67 Creating Arm joints time dependent animation functions. .. GENERATED FROM PYTHON SOURCE LINES 67-81 .. 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 82-84 Setting timelines (joints) relative position 1- Placing the main arm on the cube static base. .. GENERATED FROM PYTHON SOURCE LINES 84-86 .. code-block:: Python main_arm_animation.set_position(0, np.array([0, 1.3, 0])) .. GENERATED FROM PYTHON SOURCE LINES 87-89 2- Translating the timeline containing the sub arm to the end of the first arm. .. GENERATED FROM PYTHON SOURCE LINES 89-91 .. code-block:: Python child_arm_animation.set_position(0, np.array([12, 0, 0])) .. GENERATED FROM PYTHON SOURCE LINES 92-93 3- Translating the timeline containing the drill to the end of the sub arm. .. GENERATED FROM PYTHON SOURCE LINES 93-95 .. code-block:: Python drill_animation.set_position(0, np.array([8, 0, 0])) .. GENERATED FROM PYTHON SOURCE LINES 96-97 Setting rotation time-based evaluators .. GENERATED FROM PYTHON SOURCE LINES 97-101 .. 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 102-103 Setting camera position to observe the robot arm. .. GENERATED FROM PYTHON SOURCE LINES 103-105 .. code-block:: Python scene.camera().SetPosition(0, 0, 90) .. GENERATED FROM PYTHON SOURCE LINES 106-107 Adding the base actor to the scene .. GENERATED FROM PYTHON SOURCE LINES 107-109 .. code-block:: Python scene.add(base) .. GENERATED FROM PYTHON SOURCE LINES 110-111 Adding the main parent animation to the Timeline. .. GENERATED FROM PYTHON SOURCE LINES 111-113 .. code-block:: Python timeline.add_animation(main_arm_animation) .. GENERATED FROM PYTHON SOURCE LINES 114-115 Now we add the timeline to the ShowManager .. GENERATED FROM PYTHON SOURCE LINES 115-123 .. 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)) .. _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 `_