{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "cd9c3b5e",
            "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": "efd56a63",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy.spatial.transform import Rotation as R\nimport numpy as np",
            "outputs": []
        },
        {
            "id": "d5050793",
            "cell_type": "markdown",
            "source": "Initialize a single rotation:\n",
            "metadata": {}
        },
        {
            "id": "72fcef92",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "r = R.from_matrix([\n[0, -1, 0],\n[1, 0, 0],\n[0, 0, 1]])\nr.single",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "True"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "a2e90630",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "r.as_matrix().shape",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(3, 3)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "92720e38",
            "cell_type": "markdown",
            "source": "Initialize multiple rotations in a single object:\n",
            "metadata": {}
        },
        {
            "id": "9dba808e",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "r = R.from_matrix([\n[\n    [0, -1, 0],\n    [1, 0, 0],\n    [0, 0, 1],\n],\n[\n    [1, 0, 0],\n    [0, 0, -1],\n    [0, 1, 0],\n]])\nr.as_matrix().shape",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(2, 3, 3)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "04299bc3",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "r.single",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "False"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "f433d9be",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "len(r)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "2"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "d957f734",
            "cell_type": "markdown",
            "source": "If input matrices are not special orthogonal (orthogonal with\ndeterminant equal to +1), then a special orthogonal estimate is stored:\n",
            "metadata": {}
        },
        {
            "id": "12e04780",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "a = np.array([\n[0, -0.5, 0],\n[0.5, 0, 0],\n[0, 0, 0.5]])\nnp.linalg.det(a)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "0.125"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "85e59fd5",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "r = R.from_matrix(a)\nmatrix = r.as_matrix()\nmatrix",
            "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": "dbd0bddb",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "np.linalg.det(matrix)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "1.0"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "b6f75c98",
            "cell_type": "markdown",
            "source": "It is also possible to have a stack containing a single rotation:\n",
            "metadata": {}
        },
        {
            "id": "ff07a67b",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "r = R.from_matrix([[\n[0, -1, 0],\n[1, 0, 0],\n[0, 0, 1]]])\nr.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": "bbfe0d25",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "r.as_matrix().shape",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(1, 3, 3)"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}