{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Platonic Solids {#platonic_example}\n\nPyVista wraps the `vtk.vtkPlatonicSolidSource` filter as\n`pyvista.PlatonicSolid`{.interpreted-text role=\"func\"}.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\n\nimport pyvista as pv\nfrom pyvista import examples"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "We can either use the generic\n`PlatonicSolid() <pyvista.PlatonicSolid>`{.interpreted-text role=\"func\"}\nand specify the different kinds of solids to generate, or we can use the\nthin wrappers:\n\n-   `pyvista.Tetrahedron`{.interpreted-text role=\"func\"}\n-   `pyvista.Octahedron`{.interpreted-text role=\"func\"}\n-   `pyvista.Dodecahedron`{.interpreted-text role=\"func\"}\n-   `pyvista.Icosahedron`{.interpreted-text role=\"func\"}\n-   `pyvista.Cube`{.interpreted-text role=\"func\"} (implemented via a\n    different filter)\n\nLet\\'s generate all the Platonic solids, along with the `teapotahedron\n<pyvista.examples.downloads.download_teapot>`{.interpreted-text\nrole=\"func\"}.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "kinds = [\n    'tetrahedron',\n    'cube',\n    'octahedron',\n    'dodecahedron',\n    'icosahedron',\n]\ncenters = [\n    (0, 1, 0),\n    (0, 0, 0),\n    (0, 2, 0),\n    (-1, 0, 0),\n    (-1, 2, 0),\n]\n\nsolids = [pv.PlatonicSolid(kind, radius=0.4, center=center) for kind, center in zip(kinds, centers)]\n\n# download and align teapotahedron\nteapot = examples.download_teapot()\nteapot.rotate_x(90, inplace=True)\nteapot.rotate_z(-45, inplace=True)\nteapot.scale(0.16, inplace=True)\nteapot.points += np.array([-1, 1, 0]) - teapot.center\nsolids.append(teapot)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Now let\\'s plot them all.\n\n::: note\n::: title\nNote\n:::\n\nVTK has known issues when rendering shadows on certain window sizes. Be\nprepared to experiment with the `window_size` parameter. An initial\nwindow size of `(1000, 1000)` seems to work well, which can be manually\nresized without issue.\n:::\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "p = pv.Plotter(window_size=[1000, 1000])\nfor ind, solid in enumerate(solids):\n    # only use smooth shading for the teapot\n    smooth_shading = ind == len(solids) - 1\n    p.add_mesh(\n        solid,\n        color='silver',\n        smooth_shading=smooth_shading,\n        specular=1.0,\n        specular_power=10,\n    )\np.view_vector((5.0, 2, 3))\np.add_floor('-z', lighting=True, color='lightblue', pad=1.0)\np.enable_shadows()\np.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "The Platonic solids come with cell scalars that index each face of the\nsolids.\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.12.2"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}