{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "dd71406e",
            "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": "0217031d",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy.spatial.transform import Rotation as R",
            "outputs": []
        },
        {
            "id": "5176e645",
            "cell_type": "markdown",
            "source": "Davenport angles are a generalization of Euler angles, when we use the\ncanonical basis axes:\n",
            "metadata": {}
        },
        {
            "id": "e5a647fd",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "ex = [1, 0, 0]\ney = [0, 1, 0]\nez = [0, 0, 1]",
            "outputs": []
        },
        {
            "id": "c3ceeee9",
            "cell_type": "markdown",
            "source": "Initialize a single rotation with a given axis sequence:\n",
            "metadata": {}
        },
        {
            "id": "2960f701",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "axes = [ez, ey, ex]\nr = R.from_davenport(axes, 'extrinsic', [90, 0, 0], degrees=True)\nr.as_quat().shape",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(4,)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "9a500481",
            "cell_type": "markdown",
            "source": "It is equivalent to Euler angles in this case:\n",
            "metadata": {}
        },
        {
            "id": "46458d2a",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "r.as_euler('zyx', degrees=True)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([90.,  0., -0.])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "e83adfe5",
            "cell_type": "markdown",
            "source": "Initialize multiple rotations in one object:\n",
            "metadata": {}
        },
        {
            "id": "9d13bf7f",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "r = R.from_davenport(axes, 'extrinsic', [[90, 45, 30], [35, 45, 90]], degrees=True)\nr.as_quat().shape",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(2, 4)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "5687be54",
            "cell_type": "markdown",
            "source": "Using only one or two axes is also possible:\n",
            "metadata": {}
        },
        {
            "id": "860ef235",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "r = R.from_davenport([ez, ex], 'extrinsic', [[90, 45], [35, 45]], degrees=True)\nr.as_quat().shape",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(2, 4)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "88450998",
            "cell_type": "markdown",
            "source": "Non-canonical axes are possible, and they do not need to be normalized,\nas long as consecutive axes are orthogonal:\n",
            "metadata": {}
        },
        {
            "id": "5eae7c07",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "e1 = [2, 0, 0]\ne2 = [0, 1, 0]\ne3 = [1, 0, 1]\naxes = [e1, e2, e3]\nr = R.from_davenport(axes, 'extrinsic', [90, 45, 30], degrees=True)\nr.as_quat()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "[ 0.701057,  0.430459, -0.092296,  0.560986]"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}