{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Ellipse with units\n\nCompare the ellipse generated with arcs versus a polygonal approximation.\n\n.. only:: builder_html\n\n   This example requires :download:`basic_units.py <basic_units.py>`\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from basic_units import cm\n\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nfrom matplotlib import patches\n\nxcenter, ycenter = 0.38*cm, 0.52*cm\nwidth, height = 1e-1*cm, 3e-1*cm\nangle = -30\n\ntheta = np.deg2rad(np.arange(0.0, 360.0, 1.0))\nx = 0.5 * width * np.cos(theta)\ny = 0.5 * height * np.sin(theta)\n\nrtheta = np.radians(angle)\nR = np.array([\n    [np.cos(rtheta), -np.sin(rtheta)],\n    [np.sin(rtheta),  np.cos(rtheta)],\n    ])\n\n\nx, y = np.dot(R, [x, y])\nx += xcenter\ny += ycenter"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig = plt.figure()\nax = fig.add_subplot(211, aspect='auto')\nax.fill(x, y, alpha=0.2, facecolor='yellow',\n        edgecolor='yellow', linewidth=1, zorder=1)\n\ne1 = patches.Ellipse((xcenter, ycenter), width, height,\n                     angle=angle, linewidth=2, fill=False, zorder=2)\n\nax.add_patch(e1)\n\nax = fig.add_subplot(212, aspect='equal')\nax.fill(x, y, alpha=0.2, facecolor='green', edgecolor='green', zorder=1)\ne2 = patches.Ellipse((xcenter, ycenter), width, height,\n                     angle=angle, linewidth=2, fill=False, zorder=2)\n\n\nax.add_patch(e2)\nfig.savefig('ellipse_compare')"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig = plt.figure()\nax = fig.add_subplot(211, aspect='auto')\nax.fill(x, y, alpha=0.2, facecolor='yellow',\n        edgecolor='yellow', linewidth=1, zorder=1)\n\ne1 = patches.Arc((xcenter, ycenter), width, height,\n                 angle=angle, linewidth=2, fill=False, zorder=2)\n\nax.add_patch(e1)\n\nax = fig.add_subplot(212, aspect='equal')\nax.fill(x, y, alpha=0.2, facecolor='green', edgecolor='green', zorder=1)\ne2 = patches.Arc((xcenter, ycenter), width, height,\n                 angle=angle, linewidth=2, fill=False, zorder=2)\n\n\nax.add_patch(e2)\nfig.savefig('arc_compare')\n\nplt.show()"
      ]
    }
  ],
  "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.14.6"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}