{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "63484c02",
            "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": "f43641ba",
            "cell_type": "markdown",
            "source": "Do some imports and take some points on a cube:\n",
            "metadata": {}
        },
        {
            "id": "55433a46",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy.spatial import SphericalVoronoi, geometric_slerp\nfrom mpl_toolkits.mplot3d import proj3d\n# set input data\npoints = np.array([[0, 0, 1], [0, 0, -1], [1, 0, 0],\n                   [0, 1, 0], [0, -1, 0], [-1, 0, 0], ])",
            "outputs": []
        },
        {
            "id": "64559b61",
            "cell_type": "markdown",
            "source": "Calculate the spherical Voronoi diagram:\n",
            "metadata": {}
        },
        {
            "id": "40a0ff5a",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "radius = 1\ncenter = np.array([0, 0, 0])\nsv = SphericalVoronoi(points, radius, center)",
            "outputs": []
        },
        {
            "id": "431993a1",
            "cell_type": "markdown",
            "source": "Generate plot:\n",
            "metadata": {}
        },
        {
            "id": "29a8cea0",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "# sort vertices (optional, helpful for plotting)\nsv.sort_vertices_of_regions()\nt_vals = np.linspace(0, 1, 2000)\nfig = plt.figure()\nax = fig.add_subplot(111, projection='3d')\n# plot the unit sphere for reference (optional)\nu = 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)\n# plot generator points\nax.scatter(points[:, 0], points[:, 1], points[:, 2], c='b')\n# plot Voronoi vertices\nax.scatter(sv.vertices[:, 0], sv.vertices[:, 1], sv.vertices[:, 2],\n                   c='g')\n# indicate Voronoi regions (as Euclidean polygons)\nfor region in sv.regions:\n   n = len(region)\n   for i in range(n):\n       start = sv.vertices[region][i]\n       end = sv.vertices[region][(i + 1) % n]\n       result = geometric_slerp(start, end, t_vals)\n       ax.plot(result[..., 0],\n               result[..., 1],\n               result[..., 2],\n               c='k')\nax.azim = 10\nax.elev = 40\n_ = ax.set_xticks([])\n_ = ax.set_yticks([])\n_ = ax.set_zticks([])\nfig.set_size_inches(4, 4)\nplt.show()",
            "outputs": []
        }
    ]
}