{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "a3dda7a4",
            "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": "c0c22f64",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy.spatial.transform import Rotation as R\nimport numpy as np",
            "outputs": []
        },
        {
            "id": "f790757f",
            "cell_type": "markdown",
            "source": "A rotation can be represented as a quaternion with either scalar-last\n(default) or scalar-first component order.\nThis is shown for a single rotation:\n",
            "metadata": {}
        },
        {
            "id": "db75bd94",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "r = R.from_matrix(np.eye(3))\nr.as_quat()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([0., 0., 0., 1.])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "51d7d680",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "r.as_quat(scalar_first=True)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([1., 0., 0., 0.])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "1cf11961",
            "cell_type": "markdown",
            "source": "When multiple rotations are stored in a single Rotation object, the\nresult will be a 2-dimensional array:\n",
            "metadata": {}
        },
        {
            "id": "0d583023",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "r = R.from_rotvec([[np.pi, 0, 0], [0, 0, np.pi/2]])\nr.as_quat().shape",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(2, 4)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "7838c2ed",
            "cell_type": "markdown",
            "source": "Quaternions can be mapped from a redundant double cover of the\nrotation space to a canonical representation with a positive w term.\n",
            "metadata": {}
        },
        {
            "id": "e6ab35d1",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "r = R.from_quat([0, 0, 0, -1])\nr.as_quat()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([0. , 0. , 0. , -1.])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "89123f46",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "r.as_quat(canonical=True)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([0. , 0. , 0. , 1.])"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}