{
"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",
"* [Curve](#Curve): defines a general curve as a sequence of (x,y) coordinates\n",
"* [Gravity](#Gravity): defines a downward-pointing gravity arrow with the symbol g or user given symbol.\n",
"* [Moment](#Moment): defines a Moment arrow with text given text, center and radius\n",
"* [Text_wArrow](#Text_wArrow): Text, but an arrow is drawn from the mid part of the text to some point `arrow_tip`\n",
"* [Wheel](#Wheel): Hub and spokes Wheel given center, radius, spokes (default 10), inner_radius(default 1/5 of radius)\n",
"* [Spring](#Spring): Specify a *vertical* spring, starting at `start` and with `length` as total vertical length\n",
"* [Dashpot](#Dashpot): Specify a vertical dashpot of height `total_length` and `start` as bottom/starting point.\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": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Extra steps for YAML"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"head = \"\"\"\\\n",
"name: head\n",
"shapes:\n",
" libraries: [\"from math import tan, radians, sin, cos\",\"from pysketcher import *\", \"import numpy as np\"]\n",
"\"\"\"\n",
"myfig={}\n",
"sketch = Sketch(myfig)\n",
"sketch.append(head)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Canvas"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "222aaea654f54d6288785d838d2c940d",
"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": 9,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"line = \"\"\"\\\n",
"name: line\n",
"shapes:\n",
" A: point(-5,-5)\n",
" B: point(5,5)\n",
" line: Line(A,B)\n",
"\"\"\"\n",
"drawing_tool.erase()\n",
"sketch.append(line)\n",
"# replace 'object' by the actual one\n",
"d = myfig['line'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"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(Sketch.matplotlib2SVG()))"
]
},
{
"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": 11,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"rectangle=\"\"\"\n",
"name: rectangle\n",
"shapes:\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",
"sketch.append(rectangle)\n",
"d = myfig['rectangle'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"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(Sketch.matplotlib2SVG()))"
]
},
{
"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": 13,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"triangle=\"\"\"\n",
"name: triangle\n",
"shapes:\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",
"sketch.append(triangle)\n",
"d = myfig['triangle'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"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(Sketch.matplotlib2SVG()))"
]
},
{
"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": 15,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"circle=\"\"\"\n",
"name: circle\n",
"shapes:\n",
" circle: Circle(point(0,0),5)\n",
"\"\"\"\n",
"drawing_tool.erase()\n",
"sketch.append(circle)\n",
"d = myfig['circle'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"drawing_tool.erase()\n",
"circle = Circle(point(0,0),5)\n",
"circle.draw()\n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"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": 17,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"dwt=\"\"\"\n",
"name: dwt\n",
"shapes:\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",
"sketch.append(dwt)\n",
"d = myfig['dwt'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"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(Sketch.matplotlib2SVG()))"
]
},
{
"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": 19,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"text=\"\"\"\n",
"name: text\n",
"shapes:\n",
" text: Text(r'$c$', point(0,0))\n",
"\"\"\"\n",
"drawing_tool.erase()\n",
"sketch.append(text)\n",
"# replace 'object' by the actual one\n",
"d = myfig['text'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"drawing_tool.erase()\n",
"text = Text(r'$c$', point(0,0))\n",
"text.draw()\n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"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": 21,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"cross=\"\"\"\n",
"name: cross\n",
"shapes:\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",
"sketch.append(cross)\n",
"d = myfig['cross'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"cross1=\"\"\"\\\n",
"name: cross1\n",
"shapes:\n",
" cross1: Cross(point(0,0))\n",
"\"\"\"\n",
"drawing_tool.erase()\n",
"sketch.append(cross1)\n",
"d = myfig['cross1'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"drawing_tool.erase()\n",
"cross = Cross(point(1,0))\n",
"cross.draw()\n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"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": 24,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"axis=\"\"\"\n",
"name: axis\n",
"shapes:\n",
" axis: Axis((0,0), 5, 'x', rotation_angle=0)\n",
"\"\"\"\n",
"drawing_tool.erase()\n",
"sketch.append(axis)\n",
"d = myfig['axis'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"drawing_tool.erase()\n",
"axis = Axis((0,0), 5, 'x', rotation_angle=0)\n",
"axis.draw()\n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"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": 26,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"arc=\"\"\"\n",
"name: arc\n",
"shapes:\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",
"sketch.append(arc)\n",
"drawing_tool.erase()\n",
"d = myfig['arc'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"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(Sketch.matplotlib2SVG()))"
]
},
{
"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": 28,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"arc_wtxt=\"\"\"\n",
"name: arc_wtxt\n",
"shapes:\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",
"sketch.append(arc_wtxt)\n",
"d = myfig['arc_wtxt'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"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(Sketch.matplotlib2SVG()))"
]
},
{
"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": 30,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"arrow1=\"\"\"\n",
"name: arrow1\n",
"shapes:\n",
" start: point(0,0)\n",
" end: point(5,5)\n",
" arrow1: Arrow1(start, end, style='<->')\n",
"\"\"\"\n",
"drawing_tool.erase()\n",
"sketch.append(arrow1)\n",
"d = myfig['arrow1'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"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(Sketch.matplotlib2SVG()))"
]
},
{
"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": 32,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"force=\"\"\"\n",
"name: force\n",
"shapes:\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",
"sketch.append(force)\n",
"d = myfig['force'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"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(Sketch.matplotlib2SVG()))"
]
},
{
"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": 34,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"wall=\"\"\"\n",
"name: wall\n",
"shapes:\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",
"sketch.append(wall)\n",
"d = myfig['wall'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"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(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Curve"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[home](#Table-of-Content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### YAML"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"curve=\"\"\"\\\n",
"name: curve\n",
"shapes:\n",
" N: 100\n",
" x: np.linspace(-2.0, 2.0, N)\n",
" y: x**3\n",
" curve: Curve(x,y)\n",
"\"\"\"\n",
"drawing_tool.erase()\n",
"sketch.append(curve)\n",
"d = myfig['curve'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"drawing_tool.erase()\n",
"N = 100\n",
"x = np.linspace(-2.0, 2.0, N)\n",
"y = x**3\n",
"curve = Curve(x,y)\n",
"curve.draw()\n",
"curve.set_name(\"curve\")\n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Gravity"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[home](#Table-of-Content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### YAML"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"gravity=\"\"\"\n",
"name: gravity\n",
"shapes:\n",
" c: point(0,0)\n",
" r: 2\n",
" gravity: \n",
" formula: Gravity(c, r, text='$Mg$')\n",
"\"\"\"\n",
"drawing_tool.erase()\n",
"sketch.append(gravity)\n",
"d = myfig['gravity'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"drawing_tool.erase()\n",
"c = point(0,0)\n",
"r = 2\n",
"gravity = Gravity(c, r, text='$Mg$')\n",
"gravity.set_name(\"gravity\")\n",
"gravity.draw()\n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Moment"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[home](#Table-of-Content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### YAML"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"moment=\"\"\"\n",
"name: moment\n",
"shapes:\n",
" moment: Moment(\"$T$\", point(0,0), 2)\n",
"\"\"\"\n",
"drawing_tool.erase()\n",
"sketch.append(moment)\n",
"d = myfig['moment'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"drawing_tool.erase()\n",
"moment = Moment(\"$T$\", point(0,0), 2)\n",
"moment.shape_name=\"moment\"\n",
"moment.draw()\n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Text_wArrow"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[home](#Table-of-Content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### YAML"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"txtarrow=\"\"\"\n",
"name: txtarrow\n",
"shapes:\n",
" txtarrow: Text_wArrow(\"$Text$\", point(0,0), point(2,2))\n",
"\"\"\"\n",
"drawing_tool.erase()\n",
"sketch.append(txtarrow)\n",
"d = myfig['txtarrow'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"drawing_tool.erase()\n",
"txtarrow = Text_wArrow(\"$Text$\", point(0,0), point(2,2))\n",
"txtarrow.draw()\n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Wheel"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[home](#Table-of-Content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### YAML"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"wheel=\"\"\"\n",
"name: wheel\n",
"shapes:\n",
" wheel: Wheel(point(0,0), 5)\n",
"\"\"\"\n",
"drawing_tool.erase()\n",
"sketch.append(wheel)\n",
"d = myfig['wheel'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"drawing_tool.erase()\n",
"wheel = Wheel(point(0,0), 5)\n",
"wheel.set_name(\"wheel\")\n",
"wheel.draw()\n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Spring"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[home](#Table-of-Content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### YAML"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"spring=\"\"\"\n",
"name: spring\n",
"shapes: \n",
" spring: \n",
" formula: Spring(point(0,0),5)\n",
" style:\n",
" linecolor: black\n",
" linewidth: 1\n",
"\"\"\"\n",
"drawing_tool.erase()\n",
"sketch.append(spring)\n",
"d = myfig['spring'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"drawing_tool.erase()\n",
"spring = Spring(point(0,0),5)\n",
"spring.set_linecolor('black')\n",
"spring.set_linewidth(1)\n",
"spring.draw()\n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Dashpot"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[home](#Table-of-Content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### YAML"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"dashpot=\"\"\"\n",
"name: dashpot\n",
"shapes:\n",
" dashpot: Dashpot(point(0,0),5)\n",
"\"\"\"\n",
"drawing_tool.erase()\n",
"sketch.append(dashpot)\n",
"d = myfig['dashpot'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"drawing_tool.erase()\n",
"dashpot = Dashpot(point(0,0),5)\n",
"dashpot.set_name(\"dashpot\")\n",
"dashpot.draw()\n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"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",
"sketch.append(object)\n",
"# replace 'object' by the actual one\n",
"d = myfig['object'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"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(Sketch.matplotlib2SVG()))"
]
}
],
"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
}