{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Create PolyData {#create_poly}\n\nCreating a `pyvista.PolyData`{.interpreted-text role=\"class\"} (surface\nmesh) from vertices and faces.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\n\nimport pyvista as pv"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "A PolyData object can be created quickly from numpy arrays. The vertex\narray contains the locations of the points in the mesh and the face\narray contains the number of points of each face and the indices of the\nvertices which comprise that face.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# mesh points\nvertices = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0.5, 0.5, -1]])\n\n# mesh faces\nfaces = np.hstack(\n    [\n        [4, 0, 1, 2, 3],  # square\n        [3, 0, 1, 4],  # triangle\n        [3, 1, 2, 4],  # triangle\n    ],\n)\n\nsurf = pv.PolyData(vertices, faces)\n\n# plot each face with a different color\nsurf.plot(\n    scalars=np.arange(3),\n    cpos=[-1, 1, 0.5],\n    show_scalar_bar=False,\n    show_edges=True,\n    line_width=5,\n)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Polygonal PolyData\n\nCreate a three face polygonal mesh directly from points and faces.\n\n::: note\n::: title\nNote\n:::\n\nIt is generally more efficient to use a numpy array rather than stacking\nlists for large meshes.\n:::\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "points = np.array(\n    [\n        [0.0480, 0.0349, 0.9982],\n        [0.0305, 0.0411, 0.9987],\n        [0.0207, 0.0329, 0.9992],\n        [0.0218, 0.0158, 0.9996],\n        [0.0377, 0.0095, 0.9992],\n        [0.0485, 0.0163, 0.9987],\n        [0.0572, 0.0603, 0.9965],\n        [0.0390, 0.0666, 0.9970],\n        [0.0289, 0.0576, 0.9979],\n        [0.0582, 0.0423, 0.9974],\n        [0.0661, 0.0859, 0.9941],\n        [0.0476, 0.0922, 0.9946],\n        [0.0372, 0.0827, 0.9959],\n        [0.0674, 0.0683, 0.9954],\n    ],\n)\n\n\nface_a = [6, 0, 1, 2, 3, 4, 5]\nface_b = [6, 6, 7, 8, 1, 0, 9]\nface_c = [6, 10, 11, 12, 7, 6, 13]\nfaces = np.concatenate((face_a, face_b, face_c))\n\nmesh = pv.PolyData(points, faces)\nmesh.plot(show_edges=True, line_width=5)"
      ]
    }
  ],
  "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
}