{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "An example of the discrete gaussian curvature measure.\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "\n",
    "import trimesh\n",
    "from trimesh.curvature import (\n",
    "    discrete_gaussian_curvature_measure,\n",
    "    discrete_mean_curvature_measure,\n",
    "    sphere_ball_intersection,\n",
    ")\n",
    "\n",
    "%matplotlib inline\n",
    "\n",
    "mesh = trimesh.creation.icosphere()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "radii = np.linspace(0.1, 2.0, 10)\n",
    "gauss = np.array(\n",
    "    [\n",
    "        discrete_gaussian_curvature_measure(mesh, mesh.vertices, r)\n",
    "        / sphere_ball_intersection(1, r)\n",
    "        for r in radii\n",
    "    ]\n",
    ")\n",
    "mean = np.array(\n",
    "    [\n",
    "        discrete_mean_curvature_measure(mesh, mesh.vertices, r)\n",
    "        / sphere_ball_intersection(1, r)\n",
    "        for r in radii\n",
    "    ]\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.figure()\n",
    "plt.plot(radii, gauss.mean(axis=1))\n",
    "plt.title(\"Gaussian Curvature\")\n",
    "plt.show()\n",
    "plt.figure()\n",
    "plt.plot(radii, mean.mean(axis=1))\n",
    "plt.title(\"Mean Curvature\")\n",
    "plt.show();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
