{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "7e702c33",
            "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": "7cace2d0",
            "cell_type": "markdown",
            "source": "Interpolate four linearly-spaced values on the circumference of\na circle spanning 90 degrees:\n",
            "metadata": {}
        },
        {
            "id": "5be8f7d1",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nfrom scipy.spatial import geometric_slerp\nimport matplotlib.pyplot as plt\nfig = plt.figure()\nax = fig.add_subplot(111)\nstart = np.array([1, 0])\nend = np.array([0, 1])\nt_vals = np.linspace(0, 1, 4)\nresult = geometric_slerp(start,\n                         end,\n                         t_vals)",
            "outputs": []
        },
        {
            "id": "3448c5e6",
            "cell_type": "markdown",
            "source": "The interpolated results should be at 30 degree intervals\nrecognizable on the unit circle:\n",
            "metadata": {}
        },
        {
            "id": "88ccbc8b",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "ax.scatter(result[...,0], result[...,1], c='k')\ncircle = plt.Circle((0, 0), 1, color='grey')\nax.add_artist(circle)\nax.set_aspect('equal')\nplt.show()",
            "outputs": []
        },
        {
            "id": "ff280bc5",
            "cell_type": "markdown",
            "source": "Attempting to interpolate between antipodes on a circle is\nambiguous because there are two possible paths, and on a\nsphere there are infinite possible paths on the geodesic surface.\nNonetheless, one of the ambiguous paths is returned along\nwith a warning:\n",
            "metadata": {}
        },
        {
            "id": "70fab913",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "opposite_pole = np.array([-1, 0])\nwith np.testing.suppress_warnings() as sup:\n    sup.filter(UserWarning)\n    geometric_slerp(start,\n                    opposite_pole,\n                    t_vals)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[ 1.00000000e+00,  0.00000000e+00],\n       [ 5.00000000e-01,  8.66025404e-01],\n       [-5.00000000e-01,  8.66025404e-01],\n       [-1.00000000e+00,  1.22464680e-16]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "d2012e4c",
            "cell_type": "markdown",
            "source": "Extend the original example to a sphere and plot interpolation\npoints in 3D:\n",
            "metadata": {}
        },
        {
            "id": "ee311246",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from mpl_toolkits.mplot3d import proj3d\nfig = plt.figure()\nax = fig.add_subplot(111, projection='3d')",
            "outputs": []
        },
        {
            "id": "bfba09c7",
            "cell_type": "markdown",
            "source": "Plot the unit sphere for reference (optional):\n",
            "metadata": {}
        },
        {
            "id": "0eb0d98e",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "u = np.linspace(0, 2 * np.pi, 100)\nv = np.linspace(0, np.pi, 100)\nx = np.outer(np.cos(u), np.sin(v))\ny = np.outer(np.sin(u), np.sin(v))\nz = np.outer(np.ones(np.size(u)), np.cos(v))\nax.plot_surface(x, y, z, color='y', alpha=0.1)",
            "outputs": []
        },
        {
            "id": "0873e512",
            "cell_type": "markdown",
            "source": "Interpolating over a larger number of points\nmay provide the appearance of a smooth curve on\nthe surface of the sphere, which is also useful\nfor discretized integration calculations on a\nsphere surface:\n",
            "metadata": {}
        },
        {
            "id": "69d826a2",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "start = np.array([1, 0, 0])\nend = np.array([0, 0, 1])\nt_vals = np.linspace(0, 1, 200)\nresult = geometric_slerp(start,\n                         end,\n                         t_vals)\nax.plot(result[...,0],\n        result[...,1],\n        result[...,2],\n        c='k')\nplt.show()",
            "outputs": []
        }
    ]
}