Skip to content

Commit

Permalink
describe data format in notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
nvaytet committed Sep 19, 2024
1 parent 84b016e commit 32a2dd8
Showing 1 changed file with 75 additions and 3 deletions.
78 changes: 75 additions & 3 deletions docs/user-guide/plot-types/mesh3d-plot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"source": [
"## Loading mesh data\n",
"\n",
"We load a file containing the data to construct the [Utah teapot](https://en.wikipedia.org/wiki/Utah_teapot)."
"We load a file containing the data to construct the [Utah teapot](https://en.wikipedia.org/wiki/Utah_teapot)\n",
"(see below for a description of the data format)."
]
},
{
Expand All @@ -51,7 +52,7 @@
"source": [
"## Creating a mesh plot\n",
"\n",
"We can now send the data to the `mesh3d` function for rendering (we color the mesh according to z position):"
"We can now send the data to the [`mesh3d`](../../generated/plopp.mesh3d.html) function for rendering (we color the mesh according to z position):"
]
},
{
Expand Down Expand Up @@ -89,7 +90,78 @@
" vertices=dg[\"vertices\"],\n",
" faces=dg[\"faces\"],\n",
" vertexcolors=dg[\"vertices\"].fields.z,\n",
" edgecolor='black',\n",
" edgecolor=\"black\",\n",
")"
]
},
{
"cell_type": "markdown",
"id": "8",
"metadata": {},
"source": [
"## The data format\n",
"\n",
"The data used above contains a list of `vertices` (position vectors in 3d space),\n",
"and a list of `faces` which define how the vertices are connected to each other.\n",
"\n",
"The faces is a flat list of sequences of 3 indices that code for vertices which make up mesh triangles.\n",
"\n",
"As an example, we will construct a simple tetrahedric mesh."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9",
"metadata": {},
"outputs": [],
"source": [
"vertices = sc.vectors(\n",
" dims=[\"vertices\"],\n",
" values=[[-1, 0, 0], [0.7, 0, 1], [0.7, 0, -1], [0, 1.3, 0]],\n",
" unit=\"m\",\n",
")\n",
"faces = sc.array(\n",
" dims=[\"faces\"],\n",
" values=[\n",
" # First triangle\n",
" 0, 1, 3,\n",
" # Second triangle\n",
" 1, 2, 3,\n",
" # Third triangle\n",
" 2, 0, 3,\n",
" # Fourth triangle\n",
" 0, 2, 1,\n",
" ],\n",
")\n",
"\n",
"pp.mesh3d(\n",
" vertices=vertices,\n",
" faces=faces,\n",
" edgecolor=\"black\",\n",
")"
]
},
{
"cell_type": "markdown",
"id": "10",
"metadata": {},
"source": [
"You can then also add colors on the vertices:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "11",
"metadata": {},
"outputs": [],
"source": [
"pp.mesh3d(\n",
" vertices=vertices,\n",
" faces=faces,\n",
" vertexcolors=vertices.fields.x,\n",
" edgecolor=\"black\",\n",
")"
]
}
Expand Down

0 comments on commit 32a2dd8

Please sign in to comment.