.. 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 <sphx_glr_download_auto_examples_10_animation_viz_robot_arm_animation.py>`
        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-21

.. code-block:: Python


    import numpy as np

    import fury

    scene = fury.window.Scene()

    showm = fury.window.ShowManager(
        scene=scene, size=(900, 768), reset_camera=False, order_transparent=True
    )
    showm.initialize()









.. GENERATED FROM PYTHON SOURCE LINES 22-23

Creating robot arm components

.. GENERATED FROM PYTHON SOURCE LINES 23-45

.. code-block:: Python


    base = fury.actor.cylinder(
        np.array([[0, 0, 0]]), np.array([[0, 1, 0]]), colors=(0, 1, 0), radius=1
    )
    main_arm = fury.actor.box(np.array([[0, 0, 0]]), colors=(1, 0.5, 0), scales=(12, 1, 1))

    sub_arm = fury.actor.box(
        np.array([[0, 0, 0]]), colors=(0, 0.5, 0.8), scales=(8, 0.7, 0.7)
    )
    joint_1 = fury.actor.sphere(
        np.array([[0, 0, 0]]), colors=np.array([1, 0, 1]), radii=1.2
    )
    joint_2 = fury.actor.sphere(np.array([[0, 0, 0]]), colors=np.array([1, 0, 1]))

    end = fury.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 46-47

Setting the center of both shafts to the beginning.

.. GENERATED FROM PYTHON SOURCE LINES 47-50

.. code-block:: Python

    fury.utils.set_actor_origin(main_arm, center=np.array([-6, 0, 0]))
    fury.utils.set_actor_origin(sub_arm, center=np.array([-4, 0, 0]))








.. GENERATED FROM PYTHON SOURCE LINES 51-52

Creating a timeline

.. GENERATED FROM PYTHON SOURCE LINES 52-54

.. code-block:: Python

    timeline = fury.animation.Timeline(playback_panel=True)








.. GENERATED FROM PYTHON SOURCE LINES 55-56

Creating animations

.. GENERATED FROM PYTHON SOURCE LINES 56-63

.. code-block:: Python

    main_arm_animation = fury.animation.Animation(
        actors=[main_arm, joint_1], length=2 * np.pi
    )
    child_arm_animation = fury.animation.Animation(actors=[sub_arm, joint_2])
    drill_animation = fury.animation.Animation(actors=end)









.. GENERATED FROM PYTHON SOURCE LINES 64-65

Adding other Animations in hierarchical order

.. GENERATED FROM PYTHON SOURCE LINES 65-69

.. 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 70-71

Creating Arm joints time dependent animation functions.

.. GENERATED FROM PYTHON SOURCE LINES 71-85

.. 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 86-88

Setting timelines (joints) relative position
1- Placing the main arm on the cube static base.

.. GENERATED FROM PYTHON SOURCE LINES 88-90

.. code-block:: Python

    main_arm_animation.set_position(0, np.array([0, 1.3, 0]))








.. GENERATED FROM PYTHON SOURCE LINES 91-93

2- Translating the timeline containing the sub arm to the end of the first
arm.

.. GENERATED FROM PYTHON SOURCE LINES 93-95

.. code-block:: Python

    child_arm_animation.set_position(0, np.array([12, 0, 0]))








.. GENERATED FROM PYTHON SOURCE LINES 96-97

3- Translating the timeline containing the drill to the end of the sub arm.

.. GENERATED FROM PYTHON SOURCE LINES 97-99

.. code-block:: Python

    drill_animation.set_position(0, np.array([8, 0, 0]))








.. GENERATED FROM PYTHON SOURCE LINES 100-101

Setting rotation time-based evaluators

.. GENERATED FROM PYTHON SOURCE LINES 101-105

.. 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 106-107

Setting camera position to observe the robot arm.

.. GENERATED FROM PYTHON SOURCE LINES 107-109

.. code-block:: Python

    scene.camera().SetPosition(0, 0, 90)








.. GENERATED FROM PYTHON SOURCE LINES 110-111

Adding the base actor to the scene

.. GENERATED FROM PYTHON SOURCE LINES 111-113

.. code-block:: Python

    scene.add(base)








.. GENERATED FROM PYTHON SOURCE LINES 114-115

Adding the main parent animation to the Timeline.

.. GENERATED FROM PYTHON SOURCE LINES 115-117

.. code-block:: Python

    timeline.add_animation(main_arm_animation)








.. GENERATED FROM PYTHON SOURCE LINES 118-119

Now we add the timeline to the ShowManager

.. GENERATED FROM PYTHON SOURCE LINES 119-127

.. code-block:: Python

    showm.add_animation(timeline)

    interactive = False

    if interactive:
        showm.start()

    fury.window.record(scene=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.117 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 <viz_robot_arm_animation.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: viz_robot_arm_animation.py <viz_robot_arm_animation.py>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_