{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "2a338045",
            "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": "7f2b9951",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy.spatial.transform import RigidTransform as Tf\nfrom scipy.spatial.transform import Rotation as R\nimport numpy as np",
            "outputs": []
        },
        {
            "id": "4b496fe2",
            "cell_type": "markdown",
            "source": "Apply a single transform to a vector. Here the transform is just a\ntranslation, so the result is the vector added to the translation\nvector.\n",
            "metadata": {}
        },
        {
            "id": "cd6c70ef",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "t = np.array([1, 2, 3])\ntf = Tf.from_translation(t)\nt + np.array([1, 0, 0])",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([2, 2, 3])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "7956bc10",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "tf.apply([1, 0, 0])",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([2., 2., 3.])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "24391490",
            "cell_type": "markdown",
            "source": "Apply a single transform to a stack of vectors:\n",
            "metadata": {}
        },
        {
            "id": "3578bc7a",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "tf.apply([[1, 0, 0], [0, 1, 0]])",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[2., 2., 3.],\n       [1., 3., 3.]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "3a9fdc3b",
            "cell_type": "markdown",
            "source": "Apply the inverse of a transform to a vector, so the result is the\nnegative of the translation vector added to the vector.\n",
            "metadata": {}
        },
        {
            "id": "94c78167",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "-t + np.array([1, 0, 0])",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([0, -2, -3])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "195db697",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "tf.apply([1, 0, 0], inverse=True)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([0., -2., -3.])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "109e329b",
            "cell_type": "markdown",
            "source": "For transforms which are not just pure translations, applying it to a\nvector is the same as applying the rotation component to the vector and\nthen adding the translation component.\n",
            "metadata": {}
        },
        {
            "id": "01e593cc",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "r = R.from_euler('z', 60, degrees=True)\ntf = Tf.from_components(t, r)\nt + r.apply([1, 0, 0])",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([1.5,       2.8660254, 3.       ])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "3129eae7",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "tf.apply([1, 0, 0])",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([1.5,       2.8660254, 3.       ])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "7a9c02a1",
            "cell_type": "markdown",
            "source": "When applying the inverse of a transform, the result is the negative of\nthe translation vector added to the vector, and then rotated by the\ninverse rotation.\n",
            "metadata": {}
        },
        {
            "id": "973ae86d",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "r.inv().apply(-t + np.array([1, 0, 0]))",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([-1.73205081, -1.        , -3.        ])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "d007447c",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "tf.apply([1, 0, 0], inverse=True)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([-1.73205081, -1.        , -3.        ])"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}