{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0",
   "metadata": {},
   "source": [
    "# 4.4.2 Workplanes\n",
    "\n",
    "Workplanes allow 2D construction on planes in 3D space. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1",
   "metadata": {},
   "outputs": [],
   "source": [
    "from netgen.occ import *\n",
    "from netgen.webgui import Draw as DrawGeo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2",
   "metadata": {},
   "outputs": [],
   "source": [
    "wp = WorkPlane()\n",
    "wp.Rectangle(5,2)\n",
    "face = wp.Face()\n",
    "DrawGeo(face);"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3",
   "metadata": {},
   "source": [
    "A workplane is defined by a local coordinate system given by an 'Axes' object. This is specified by its origin, the normal vector to the plane, and the horizontal direction (i.e. the local x direction)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4",
   "metadata": {},
   "outputs": [],
   "source": [
    "f1 = WorkPlane(Axes((0,0,0), n=Z, h=X)).Rectangle(2,1).Face()\n",
    "f2 = WorkPlane(Axes((0,1,0), n=-Y, h=X)).Rectangle(2,1).Face()\n",
    "f3 = WorkPlane(Axes((0,0,0), n=X, h=Y)).Rectangle(1,1).Face()\n",
    "DrawGeo (f1+f2+f3);"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5",
   "metadata": {},
   "source": [
    "The workplane stores the current position and direction. With `Line` we draw a straight line of given length in the current direction, with `Arc` we draw a tangential arc of given radius and angle."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6",
   "metadata": {},
   "outputs": [],
   "source": [
    "wp = WorkPlane()\n",
    "for i in range(6):\n",
    "    wp.Line(1).Rotate(60)\n",
    "wp.MoveTo(3,0)\n",
    "for i in range(6):\n",
    "    wp.Line(0.6).Arc(0.4, 60)\n",
    "face = wp.Face()\n",
    "DrawGeo(face);"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7",
   "metadata": {},
   "source": [
    "We can draw several wires. Holes a defined by reveriting the orientation of an wire:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8",
   "metadata": {},
   "outputs": [],
   "source": [
    "wp=WorkPlane().RectangleC(2,1) \\\n",
    "    .Circle(0.5,0,0.2).Reverse() \\\n",
    "    .Circle(-0.5,0,0.2).Reverse()\n",
    "DrawGeo(Compound(wp.Wires()))\n",
    "DrawGeo(wp.Face());"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9",
   "metadata": {},
   "source": [
    "Faces can be extruded"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "10",
   "metadata": {},
   "outputs": [],
   "source": [
    "face = WorkPlane().RectangleC(2,1).RectangleC(1.8,0.8).Reverse().Face()\n",
    "frame = face.Extrude(1)\n",
    "DrawGeo(frame);"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "11",
   "metadata": {},
   "source": [
    "and also revolved:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "12",
   "metadata": {},
   "outputs": [],
   "source": [
    "face = WorkPlane().MoveTo(10,0).Line(18).Arc(2,90).Line(6).Arc(2,90) \\\n",
    "    .Line(18).Rotate(90).Line(2).Rotate(90).Line(10) \\\n",
    "    .Arc(3,-180).Line(10).Close().Face()\n",
    "p = face.Revolve(Axis((0,0,0),Y),180)\n",
    "DrawGeo(p);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "13",
   "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.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
