{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib widget" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{\n", "'body': {\n", " 'arc': \"181 (x,y) coords fillcolor='b' fillpattern=''\",},\n", "'rod': {\n", " 'line': \"2 (x,y) coords\",},\n", "'vertical': {\n", " 'line': \"2 (x,y) coords linecolor='k' linewidth=1 linestyle='dashed'\",},\n", "'theta': {\n", " 'arc': {\n", " 'arc': \"181 (x,y) coords\",},\n", " 'text': \"Text at (1.49593,4.58745)\",},\n", "'path': {\n", " 'arc': \"181 (x,y) coords linecolor='k' linewidth=1 linestyle='dashed'\",},\n", "'g': {\n", " 'arrow': {\n", " 'line': \"2 (x,y) coords linecolor='k' arrow='->'\",},\n", " 'text': \"Text at (5,4.11333)\",},\n", "'L': {\n", " 'arrow': {\n", " 'arrow': {\n", " 'line': \"2 (x,y) coords linecolor='k' linewidth=1 arrow='<->'\",},},\n", " 'text': \"Text at (2.93892,4.31343)\",},\n", "'m': \"Text at (4.53533,1.73676)\",}" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from pysketcher import *\n", "\n", "H = 7.\n", "W = 6.\n", "\n", "drawing_tool.set_coordinate_system(xmin=0, xmax=W,\n", " ymin=0, ymax=H,\n", " axis=False)\n", "#drawing_tool.set_grid(True)\n", "drawing_tool.set_linecolor('blue')\n", "\n", "L = 5*H/7 # length\n", "P = (W/6, 0.85*H) # rotation point\n", "a = 40 # angle\n", "\n", "vertical = Line(P, P-point(0,L))\n", "path = Arc(P, L, -90, a)\n", "angle = Arc_wText(r'$\\theta$', P, L/4, -90, a, text_spacing=1/30.)\n", "\n", "rod = Line(P, P + L*point(sin(radians(a)), -L*cos(radians(a))))\n", "# or shorter (and more reliable)\n", "mass_pt = path.geometric_features()['end']\n", "rod = Line(P, mass_pt)\n", "\n", "mass = Circle(center=mass_pt, radius=L/20.)\n", "mass.set_filled_curves(color='blue')\n", "rod_vec = rod.geometric_features()['end'] - \\\n", " rod.geometric_features()['start']\n", "unit_rod_vec = unit_vec(rod_vec)\n", "mass_symbol = Text('$m$', mass_pt + L/10*unit_rod_vec)\n", "\n", "length = Distance_wText(P, mass_pt, '$L$')\n", "# Displace length indication\n", "length.translate(L/15*point(cos(radians(a)), sin(radians(a))))\n", "gravity = Gravity(start=P+point(0.8*L,0), length=L/3)\n", "\n", "def set_dashed_thin_blackline(*objects):\n", " \"\"\"Set linestyle of objects to dashed, black, width=1.\"\"\"\n", " for obj in objects:\n", " obj.set_linestyle('dashed')\n", " obj.set_linecolor('black')\n", " obj.set_linewidth(1)\n", "\n", "set_dashed_thin_blackline(vertical, path)\n", "\n", "fig = Composition(\n", " {'body': mass, 'rod': rod,\n", " 'vertical': vertical, 'theta': angle, 'path': path,\n", " 'g': gravity, 'L': length, 'm': mass_symbol})\n", "\n", "fig.draw()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "18d9de304de444c197579e4b6bd668be", "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": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{\n", "'mg': {\n", " 'arrow': {\n", " 'line': \"2 (x,y) coords arrow='->'\",},\n", " 'text': \"Text at (4.21394,0.949778)\",},\n", "'S': {\n", " 'arrow': {\n", " 'line': \"2 (x,y) coords arrow='->'\",},\n", " 'text': \"Text at (3.32263,3.45652)\",},\n", "'rod': {\n", " 'line': \"2 (x,y) coords linecolor='k' linewidth=1 linestyle='dashed'\",},\n", "'vertical': {\n", " 'line': \"2 (x,y) coords linecolor='k' linewidth=1 linestyle='dashed'\",},\n", "'theta': {\n", " 'arc': {\n", " 'arc': \"181 (x,y) coords\",},\n", " 'text': \"Text at (1.35342,4.97898)\",},\n", "'body': {\n", " 'arc': \"181 (x,y) coords fillcolor='b' fillpattern=''\",},\n", "'m': \"Text at (4.53533,1.73676)\",}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Draw free body diagram in several different versions\n", "# (note that we build body_diagram, erase and draw,\n", "# add elements to body_diagram, erase and draw, and so on)\n", "\n", "drawing_tool.erase()\n", "\n", "drawing_tool.set_linecolor('black')\n", "\n", "rod_start = rod.geometric_features()['start'] # Point P\n", "vertical2 = Line(rod_start, rod_start + point(0,-L/3))\n", "set_dashed_thin_blackline(vertical2)\n", "set_dashed_thin_blackline(rod)\n", "angle2 = Arc_wText(r'$\\theta$', rod_start, L/6, -90, a,\n", " text_spacing=1/30.)\n", "\n", "mg_force = Force(mass_pt, mass_pt + L/5*point(0,-1),\n", " '$mg$', text_pos='end')\n", "rod_force = Force(mass_pt, mass_pt - L/3*unit_vec(rod_vec),\n", " '$S$', text_pos='end',\n", " text_spacing=(0.03, 0.01))\n", "air_force = Force(mass_pt, mass_pt -\n", " L/6*unit_vec((rod_vec[1], -rod_vec[0])),\n", " '$\\sim|v|v$', text_pos='end',\n", " text_spacing=(0.04,0.005))\n", "\n", "body_diagram = Composition(\n", " {'mg': mg_force, 'S': rod_force, 'rod': rod,\n", " 'vertical': vertical2, 'theta': angle2,\n", " 'body': mass, 'm': mass_symbol})\n", "\n", "body_diagram.draw()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "18d9de304de444c197579e4b6bd668be", "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": 6, "metadata": {}, "outputs": [], "source": [ "drawing_tool.adjust_coordinate_system(body_diagram.minmax_coordinates(), 90)\n", "drawing_tool.display('Free body diagram')" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "drawing_tool.erase()\n", "body_diagram['air'] = air_force\n", "body_diagram.draw()\n", "drawing_tool.display('Free body diagram')" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "drawing_tool.erase()\n", "x0y0 = Text('$(x_0,y_0)$', P + point(-0.4,-0.1))\n", "ir = Force(P, P + L/10*unit_vec(rod_vec),\n", " r'$\\boldsymbol{i}_r$', text_pos='end',\n", " text_spacing=(0.015,0))\n", "ith = Force(P, P + L/10*unit_vec((-rod_vec[1], rod_vec[0])),\n", " r'$\\boldsymbol{i}_{\\theta}$', text_pos='end',\n", " text_spacing=(0.02,0.005))\n", "\n", "body_diagram['ir'] = ir\n", "body_diagram['ith'] = ith\n", "body_diagram['origin'] = x0y0\n", "\n", "body_diagram.draw()\n", "drawing_tool.display('Free body diagram')" ] }, { "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 }