{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "405194ab",
            "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": "5df4fc6c",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy.spatial.transform import RigidTransform as Tf\nimport numpy as np",
            "outputs": []
        },
        {
            "id": "746d70ce",
            "cell_type": "markdown",
            "source": "A power of 2 returns the transform composed with itself:\n",
            "metadata": {}
        },
        {
            "id": "0d86a4df",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "tf = Tf.from_translation([1, 2, 3])\n(tf ** 2).translation",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([2., 4., 6.])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "12f3d723",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "(tf ** 2).as_matrix()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[1., 0., 0., 2.],\n       [0., 1., 0., 4.],\n       [0., 0., 1., 6.],\n       [0., 0., 0., 1.]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "bfb7914c",
            "cell_type": "markdown",
            "source": "A negative power returns the inverse of the transform raised to the\nabsolute value of `n`:\n",
            "metadata": {}
        },
        {
            "id": "1f7ca864",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "(tf ** -2).translation",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([-2., -4., -6.])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "4281005e",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "np.allclose((tf ** -2).as_matrix(), (tf.inv() ** 2).as_matrix(),\n            atol=1e-12)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "True"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "39cdcfe2",
            "cell_type": "markdown",
            "source": "A power of 0 returns the identity transform:\n",
            "metadata": {}
        },
        {
            "id": "b8c8baa9",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "(tf ** 0).as_matrix()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[1., 0., 0., 0.],\n       [0., 1., 0., 0.],\n       [0., 0., 1., 0.],\n       [0., 0., 0., 1.]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "1d20df0b",
            "cell_type": "markdown",
            "source": "A power of 1 returns a copy of the original transform:\n",
            "metadata": {}
        },
        {
            "id": "f54daf39",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "(tf ** 1).as_matrix()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[1., 0., 0., 1.],\n       [0., 1., 0., 2.],\n       [0., 0., 1., 3.],\n       [0., 0., 0., 1.]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "9eb56267",
            "cell_type": "markdown",
            "source": "A fractional power returns a transform with a scaled rotation and\ntranslated along the screw axis. Here we take the square root of the\ntransform, which when squared recovers the original transform:\n",
            "metadata": {}
        },
        {
            "id": "02d06078",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "tf_half = (tf ** 0.5)\ntf_half.translation",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([0.5, 1., 1.5])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "ada16e97",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "(tf_half ** 2).as_matrix()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[1., 0., 0., 1.],\n       [0., 1., 0., 2.],\n       [0., 0., 1., 3.],\n       [0., 0., 0., 1.]])"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}