{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Reference" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Collection of snippets defining all the elementary objects of shapes.py" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Table of Content" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* [Line](#Line): defines a line providing start and end point\n", "* [Rectangle](#Rectangle): defines a rectangle providing bottom left corner, x dimension, y dimension\n", "* [Triangle](#Triangle): defines a triangle providing three corner\n", "* [Circle](#Circle): defines a circle proving center and radius\n", "* [Distance with text](#Distance-with-text): defines a sizing mark with a label \n", "* [Text](#Text): defines a given text positionned at the provided point\n", "* [Cross](#Cross): defines a cross positionned at the provided point\n", "* [Axis](#Axis): defines an axis at the given point with a given label\n", "* [Arc](#Arc): defines an Arc providing a center point, a radius, a starting angle and an angle (rotates clock-wise)\n", "* [Arc_wText](#Arc_wText): defines an arc with text positionned left (moving clock-wise) of arc half-way\n", "* [Arrow1](#Arrow1): defines a line with arrow(s) given starting and ending point and arrow termination(s) ->, \\<->, \\<-\n", "* [Force](#Force): defines an Indication of a force by an arrow and a text (symbol)\n", "* [Wall](#Wall): defines an hached box given starting, ending point and thickness, filled with a pattern \n", "* [](#)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Setup" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ " %matplotlib widget" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from pysketcher import *" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "drawing_tool.set_coordinate_system(xmin=-10, xmax=10,ymin=-10, ymax=10,axis=True)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "from IPython.display import SVG, display" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "from math import tan, radians, sin, cos" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Extra steps for YAML" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "head = \"\"\"\\\n", "libraries: [\"from math import tan, radians, sin, cos\",\"from pysketcher import *\"]\n", "\"\"\"\n", "myfig={}\n", "sketchParse(head,myfig)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Canvas" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "6f43cf6e56d74ae7ab2e8e26962ca62b", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "drawing_tool.mpl.gcf().canvas" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Line" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[home](#Table-of-Content)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### YAML" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "line=\"\"\"\n", "A: point(-5,-5)\n", "B: point(5,5)\n", "line: Line(A,B)\n", "\"\"\"\n", "drawing_tool.erase()\n", "sketchParse(line,myfig)\n", "# replace 'object' by the actual one\n", "d = myfig['line'].draw() \n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Python" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "drawing_tool.erase()\n", "A = point(-5,-5)\n", "B = point(5,5)\n", "line = Line(A,B)\n", "line.draw()\n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Rectangle" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[home](#Table-of-Content)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### YAML" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "rectangle=\"\"\"\n", "L: 8\n", "h: 5\n", "p: point(-(L/2),-(h/2))\n", "rectangle: Rectangle(p,L,h)\n", "\"\"\"\n", "drawing_tool.erase()\n", "sketchParse(rectangle,myfig)\n", "# replace 'object' by the actual one\n", "d = myfig['rectangle'].draw() \n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Python" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "drawing_tool.erase()\n", "L = 8\n", "h = 5\n", "p = point(-(L/2),-(h/2))\n", "rectangle = Rectangle(p,L,h)\n", "rectangle.draw()\n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Triangle" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[home](#Table-of-Content)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### YAML" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "triangle=\"\"\"\n", "L: 3.0\n", "W: 4.0\n", "triangle: Triangle(p1=(W/2,0), p2=(3*W/2,W/2), p3=(4*W/5.,L))\n", "\"\"\"\n", "drawing_tool.erase()\n", "sketchParse(triangle,myfig)\n", "# replace 'object' by the actual one\n", "d = myfig['triangle'].draw() \n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Python" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "drawing_tool.erase()\n", "L = 3.0\n", "W = 4.0\n", "triangle = Triangle(p1=(W/2,0), p2=(3*W/2,W/2), p3=(4*W/5.,L))\n", "triangle.draw()\n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Circle" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[home](#Table-of-Content)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### YAML" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "circle=\"\"\"\n", "circle: Circle(point(0,0),5)\n", "\"\"\"\n", "drawing_tool.erase()\n", "sketchParse(circle,myfig)\n", "# replace 'object' by the actual one\n", "d = myfig['circle'].draw() \n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Python" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "drawing_tool.erase()\n", "circle = Circle(point(0,0),5)\n", "circle.draw()\n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Distance with text" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[home](#Table-of-Content)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### YAML" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dwt=\"\"\"\n", "fontsize: 14\n", "t: r'$ 2\\pi R^2 $' # sample text\n", "dwt: Distance_wText((-4,0), (8, 5), t, fontsize)\n", "\"\"\"\n", "drawing_tool.erase()\n", "sketchParse(dwt,myfig)\n", "# replace 'object' by the actual one\n", "d = myfig['dwt'].draw() \n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Python" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "drawing_tool.erase()\n", "fontsize=14\n", "t = r'$ 2\\pi R^2 $' # sample text\n", "dwt = Distance_wText((-4,0), (8, 5), t, fontsize)\n", "dwt.draw()\n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Text" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[home](#Table-of-Content)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### YAML" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "text=\"\"\"\n", "text: Text(r'$c$', point(0,0))\n", "\"\"\"\n", "drawing_tool.erase()\n", "sketchParse(text,myfig)\n", "# replace 'object' by the actual one\n", "d = myfig['text'].draw() \n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Python" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "drawing_tool.erase()\n", "text = Text(r'$c$', point(0,0))\n", "text.draw()\n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Cross" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[home](#Table-of-Content)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### YAML" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cross=\"\"\"\n", "c: point(0,0)\n", "l: 0.1\n", "line1: Line(c+point(-l,l),c+point(l,-l))\n", "line2: Line(c+point(l,l), c+point(-l,-l))\n", "cross: \n", " formula: \"Composition({'line1': line1, 'line2': line2})\"\n", " style:\n", " linecolor: black\n", " linewidth: 1\n", "\"\"\"\n", "drawing_tool.erase()\n", "sketchParse(cross,myfig)\n", "d = myfig['cross'].draw() \n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cross1=\"\"\"\n", "cross1: Cross(point(0,0))\n", "\"\"\"\n", "drawing_tool.erase()\n", "sketchParse(cross1,myfig)\n", "d = myfig['cross1'].draw() \n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Python" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "drawing_tool.erase()\n", "cross = Cross(point(1,0))\n", "cross.draw()\n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Axis" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[home](#Table-of-Content)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### YAML" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "axis=\"\"\"\n", "axis: Axis((0,0), 5, 'x', rotation_angle=0)\n", "\"\"\"\n", "drawing_tool.erase()\n", "sketchParse(axis,myfig)\n", "# replace 'object' by the actual one\n", "d = myfig['axis'].draw() \n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Python" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "drawing_tool.erase()\n", "axis = Axis((0,0), 5, 'x', rotation_angle=0)\n", "axis.draw()\n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Arc" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[home](#Table-of-Content)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### YAML" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "arc=\"\"\"\n", "center: point(0,0)\n", "radius: 1\n", "angle: 120\n", "start_angle: 180-angle\n", "arc_angle: angle\n", "arc: Arc(center, radius, start_angle, arc_angle)\n", "\"\"\"\n", "sketchParse(arc,myfig)\n", "d = myfig['arc'].draw() \n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Python" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "drawing_tool.erase()\n", "center = point(0,0)\n", "radius = 1\n", "angle = 120\n", "start_angle = 180-angle\n", "arc_angle = angle\n", "arc = Arc(center, radius, start_angle, arc_angle)\n", "arc.draw()\n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Arc_wText" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[home](#Table-of-Content)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### YAML" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "arc_wtxt=\"\"\"\n", "center: point(0,0)\n", "radius: 1\n", "angle: 120\n", "start_angle: 90-angle\n", "arc_angle: angle\n", "arc_wtxt: \"Arc_wText(r'$theta$', center, radius, start_angle, arc_angle)\"\n", "\"\"\"\n", "drawing_tool.erase()\n", "sketchParse(arc_wtxt,myfig)\n", "d = myfig['arc_wtxt'].draw() \n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Python" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "drawing_tool.erase()\n", "center = point(0,0)\n", "radius = 1\n", "angle = 120\n", "start_angle = 180-angle\n", "arc_angle = angle\n", "arc_wtxt = Arc_wText(r'$\\theta$', center, radius, start_angle, arc_angle)\n", "arc_wtxt.draw()\n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Arrow1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[home](#Table-of-Content)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### YAML" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "arrow1=\"\"\"\n", "start: point(0,0)\n", "end: point(5,5)\n", "arrow1: Arrow1(start, end, style='<->')\n", "\"\"\"\n", "drawing_tool.erase()\n", "sketchParse(arrow1,myfig)\n", "d = myfig['arrow1'].draw() \n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Python" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "drawing_tool.erase()\n", "start = point(0,0)\n", "end = point(5,5)\n", "arrow1 = Arrow1(start, end, style='<->')\n", "arrow1.draw()\n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Force" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[home](#Table-of-Content)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### YAML" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "force=\"\"\"\n", "x: 0\n", "y: 0\n", "contact: point(x, y)\n", "vector: point(-3,-5)\n", "force: Force(contact - vector, contact, r'$Force$', text_pos='start')\n", "\"\"\"\n", "drawing_tool.erase()\n", "sketchParse(force,myfig)\n", "# replace 'object' by the actual one\n", "d = myfig['force'].draw() \n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Python" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "drawing_tool.erase()\n", "x = 0\n", "y = 0\n", "contact = point(x, y)\n", "vector = point(-3,-5)\n", "force = Force(contact - vector, contact, r'$Force$', text_pos='start')\n", "force.draw()\n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Wall" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[home](#Table-of-Content)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### YAML" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wall=\"\"\"\n", "theta: 30\n", "L: 8\n", "B: point(L-4,-2) # wall right end\n", "A: point(-4,tan(radians(theta))*L-2) # wall left end\n", "wall: \n", " formula: Wall(x=[A[0], B[0]], y=[A[1], B[1]], thickness=-0.5,transparent=False)\n", " style:\n", " linecolor: black\n", "\"\"\"\n", "drawing_tool.erase()\n", "sketchParse(wall,myfig)\n", "# replace 'object' by the actual one\n", "d = myfig['wall'].draw() \n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Python" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "drawing_tool.erase()\n", "theta = 30\n", "L = 8\n", "B = point(L-4,-2) # wall right end\n", "A = point(-4,tan(radians(theta))*L-2) # wall left end\n", "wall= Wall(x=[A[0], B[0]], y=[A[1], B[1]], thickness=-0.5,transparent=False)\n", "wall.set_linecolor('black')\n", "wall.draw()\n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Object" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[home](#Table-of-Content)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### YAML" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "object=\"\"\"\n", "TBC:\n", "\"\"\"\n", "drawing_tool.erase()\n", "sketchParse(object,myfig)\n", "# replace 'object' by the actual one\n", "d = myfig['object'].draw() \n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Python" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "drawing_tool.erase()\n", "# put code\n", "object = ...\n", "object.draw()\n", "drawing_tool.display()\n", "display(SVG(sketch2SVG()))" ] } ], "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.5" } }, "nbformat": 4, "nbformat_minor": 4 }