{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Oscillator Sketch1" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib widget" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "\"\"\"Draw mechanical vibration system.\"\"\"\n", "\n", "from pysketcher import *\n", "\n", "L = 12.\n", "H = L/6\n", "W = L/6\n", "\n", "xmax = L\n", "drawing_tool.set_coordinate_system(xmin=-L, xmax=xmax,\n", " ymin=-1, ymax=L+H,\n", " axis=False,\n", " instruction_file='tmp_mpl.py')\n", "x = 0\n", "drawing_tool.set_linecolor('black')\n", "\n", "def make_dashpot(x):\n", " d_start = (-L,2*H)\n", " d = Dashpot(start=d_start, total_length=L+x, width=W,\n", " bar_length=3*H/2, dashpot_length=L/2, piston_pos=H+x)\n", " d.rotate(-90, d_start)\n", " return d\n", "\n", "def make_spring(x):\n", " s_start = (-L,4*H)\n", " s = Spring(start=s_start, length=L+x, bar_length=3*H/2, teeth=True)\n", " s.rotate(-90, s_start)\n", " return s\n", "\n", "d = make_dashpot(0)\n", "s = make_spring(0)\n", "\n", "M = Rectangle((0,H), 4*H, 4*H).set_linewidth(4)\n", "left_wall = Rectangle((-L,0),H/10,L).set_filled_curves(pattern='/')\n", "ground = Wall(x=[-L/2,L], y=[0,0], thickness=-H/10)\n", "wheel1 = Circle((H,H/2), H/2)\n", "wheel2 = wheel1.copy()\n", "wheel2.translate(point(2*H, 0))\n", "\n", "fontsize = 18\n", "text_m = Text('$m$', (2*H, H+2*H), fontsize=fontsize)\n", "text_ku = Text('$ku$', (-L/2, H+4*H), fontsize=fontsize)\n", "text_bv = Text(\"$bu'$\", (-L/2, H), fontsize=fontsize)\n", "x_axis = Axis((2*H, L), H, '$u(t)$', fontsize=fontsize,\n", " label_spacing=(0.04, -0.01))\n", "x_axis_start = Line((2*H, L-H/4), (2*H, L+H/4)).set_linewidth(4)\n", "\n", "fig = Composition({\n", " 'spring': s, 'mass': M, 'left wall': left_wall,\n", " 'ground': ground, 'wheel1': wheel1, 'wheel2': wheel2,\n", " 'text_m': text_m, 'text_ku': text_ku,\n", " 'x_axis': x_axis, 'x_axis_start': x_axis_start})\n", "\n", "fig.draw()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "5b6519e875354bbf82e2356bcf09d158", "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": "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.5" } }, "nbformat": 4, "nbformat_minor": 4 }