{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "b702f824",
            "cell_type": "markdown",
            "source": "<div class='alert alert-warning'>\n\nSciPy's interactive examples with Jupyterlite are experimental and may not always work as expected. Execution of cells containing imports may result in large downloads (up to 60MB of content for the first import from SciPy). Load times when importing from SciPy may take roughly 10-20 seconds. If you notice any problems, feel free to open an [issue](https://github.com/scipy/scipy/issues/new/choose).\n\n</div>",
            "metadata": {}
        },
        {
            "id": "2aade4e9",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy.spatial.transform import Rotation as R\nimport numpy as np",
            "outputs": []
        },
        {
            "id": "c1bdbb93",
            "cell_type": "markdown",
            "source": "Composition of two single rotations:\n",
            "metadata": {}
        },
        {
            "id": "82e62b57",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "p = R.from_quat([0, 0, 1, 1])\nq = R.from_quat([1, 0, 0, 1])\np.as_matrix()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[ 0., -1.,  0.],\n       [ 1.,  0.,  0.],\n       [ 0.,  0.,  1.]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "7bbdb4fb",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "q.as_matrix()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[ 1.,  0.,  0.],\n       [ 0.,  0., -1.],\n       [ 0.,  1.,  0.]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "ff7530ae",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "r = p * q\nr.as_matrix()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[0., 0., 1.],\n       [1., 0., 0.],\n       [0., 1., 0.]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "0cca7ceb",
            "cell_type": "markdown",
            "source": "Composition of two objects containing equal number of rotations:\n",
            "metadata": {}
        },
        {
            "id": "ac7736fd",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "p = R.from_quat([[0, 0, 1, 1], [1, 0, 0, 1]])\nq = R.from_rotvec([[np.pi/4, 0, 0], [-np.pi/4, 0, np.pi/4]])\np.as_quat()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[0.        , 0.        , 0.70710678, 0.70710678],\n       [0.70710678, 0.        , 0.        , 0.70710678]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "c2e0b312",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "q.as_quat()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[ 0.38268343,  0.        ,  0.        ,  0.92387953],\n       [-0.37282173,  0.        ,  0.37282173,  0.84971049]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "a36cfe09",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "r = p * q\nr.as_quat()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[ 0.27059805,  0.27059805,  0.65328148,  0.65328148],\n       [ 0.33721128, -0.26362477,  0.26362477,  0.86446082]])"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}