|
|
@@ -0,0 +1,327 @@
|
|
|
+{
|
|
|
+ "cells": [
|
|
|
+ {
|
|
|
+ "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": [
|
|
|
+ "from ipywidgets import FloatSlider, AppLayout, Label, HBox, Button"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "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": [
|
|
|
+ "myfig={}"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 7,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "gw = \"\"\"\\\n",
|
|
|
+ "libraries: [\"from math import tan, radians, sin, cos\",\"from pysketcher import *\"]\n",
|
|
|
+ "fontsize: 18\n",
|
|
|
+ "g: 9.81 # constant gravity\n",
|
|
|
+ "theta: 30.0 # inclined plane angle\n",
|
|
|
+ "L: 10.0 # sketch sizing parameter\n",
|
|
|
+ "a: 1.0 #\n",
|
|
|
+ "xmin: 0.0 # sketech min Abscissa\n",
|
|
|
+ "ymin: -3.0 # sketech min Ordinate \n",
|
|
|
+ "rl: 2.0 # rectangle width\n",
|
|
|
+ "rL: 1.0 # rectangle length\n",
|
|
|
+ "setframe: # sketch setup\n",
|
|
|
+ " action: \"drawing_tool.set_coordinate_system(xmin=xmin, xmax=xmin+1.5*L,ymin=ymin, ymax=ymin+1.5*L,instruction_file='tmp_mpl_friction.py')\"\n",
|
|
|
+ "setblackline: # default frame values and actions\n",
|
|
|
+ " action: \"drawing_tool.set_linecolor('black')\"\n",
|
|
|
+ "B: point(a+L,0) # wall right end\n",
|
|
|
+ "A: point(a,tan(radians(theta))*L) # wall left end\n",
|
|
|
+ "normal_vec: point(sin(radians(theta)),cos(radians(theta))) # Vector normal to wall\n",
|
|
|
+ "tangent_vec: point(cos(radians(theta)),-sin(radians(theta))) # Vector tangent to wall\n",
|
|
|
+ "help_line: Line(A,B) # wall line\n",
|
|
|
+ "x: a + 3*L/10.\n",
|
|
|
+ "y: help_line(x=x) \n",
|
|
|
+ "contact: point(x, y) \n",
|
|
|
+ "c: contact + rL/2*normal_vec\n",
|
|
|
+ "rectangle: \n",
|
|
|
+ " formula: Rectangle(contact, rl, rL)\n",
|
|
|
+ " style:\n",
|
|
|
+ " linecolor: blue\n",
|
|
|
+ " filled_curves: blue\n",
|
|
|
+ " transform: [\"rotate(-theta, contact)\",\"translate(-rl/2*tangent_vec)\"]\n",
|
|
|
+ "N: \n",
|
|
|
+ " formula: Force(contact - rl*normal_vec, contact, r'$N$', text_pos='start')\n",
|
|
|
+ " style:\n",
|
|
|
+ " linecolor: black\n",
|
|
|
+ "mg: \n",
|
|
|
+ " formula: Gravity(c, rl, text='$Mg$')\n",
|
|
|
+ " style:\n",
|
|
|
+ " linecolor: black\n",
|
|
|
+ "wheel: \n",
|
|
|
+ " formula: \"Composition({'outer': rectangle})\" \n",
|
|
|
+ " style:\n",
|
|
|
+ " shadow: 1\n",
|
|
|
+ "body: \n",
|
|
|
+ " formula: \"Composition({'wheel': wheel, 'N': N, 'mg': mg})\"\n",
|
|
|
+ " style:\n",
|
|
|
+ " linecolor: black\n",
|
|
|
+ "mB:\n",
|
|
|
+ " formula: Text(r'$B$',B)\n",
|
|
|
+ "mA:\n",
|
|
|
+ " formula: Text(r'$A$', A)\n",
|
|
|
+ "wall: \n",
|
|
|
+ " formula: Wall(x=[A[0], B[0]], y=[A[1], B[1]], thickness=-0.25,transparent=False)\n",
|
|
|
+ " style:\n",
|
|
|
+ " linecolor: black \n",
|
|
|
+ "angle: \n",
|
|
|
+ " formula: \"Arc_wText(r'$<bslash>theta$', center=B, radius=3, start_angle=180-theta, arc_angle=theta, fontsize=fontsize)\"\n",
|
|
|
+ " style:\n",
|
|
|
+ " linecolor: black\n",
|
|
|
+ " linewidth: 1\n",
|
|
|
+ "ground: \n",
|
|
|
+ " formula: Line((B[0]-L/10., 0), (B[0]-L/2.,0))\n",
|
|
|
+ " stlye:\n",
|
|
|
+ " linecolor: black\n",
|
|
|
+ " linestyle: dashed\n",
|
|
|
+ " linewidth: 1\n",
|
|
|
+ "x_const: \n",
|
|
|
+ " formula: Line(contact, contact + point(0,4))\n",
|
|
|
+ " style:\n",
|
|
|
+ " linestyle: dotted\n",
|
|
|
+ " transform: rotate(-theta, contact)\n",
|
|
|
+ "x_axis: \n",
|
|
|
+ " formula: \"Axis(start=contact+ 2*rl*normal_vec, length=2*rl,label='$x$', rotation_angle=-theta)\"\n",
|
|
|
+ "plan: \n",
|
|
|
+ " formula: \"Composition({'body': body, 'angle': angle, 'inclined wall': wall, 'x start': x_const, 'x axis': x_axis, 'mA': mA, 'mB': mB})\"\n",
|
|
|
+ "friction: \n",
|
|
|
+ " formula: \"Composition({'plan': plan, 'ground': ground})\"\n",
|
|
|
+ "\"\"\""
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 8,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "sketchParse(gw,myfig)"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 9,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "d = myfig['friction'].draw()"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 10,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "drawing_tool.display()"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 11,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "angle = myfig['theta']\n",
|
|
|
+ "def doright(change):\n",
|
|
|
+ " global angle\n",
|
|
|
+ " rotate(-5)\n",
|
|
|
+ " angle += 5\n",
|
|
|
+ "def doleft(change):\n",
|
|
|
+ " global angle\n",
|
|
|
+ " rotate(5)\n",
|
|
|
+ " angle -= 5\n",
|
|
|
+ "def rotate(theta):\n",
|
|
|
+ " global angle\n",
|
|
|
+ " drawing_tool.erase()\n",
|
|
|
+ " myfig['plan']['angle'].changeAngles(180-angle,angle)\n",
|
|
|
+ " myfig['plan'].rotate(theta,myfig['B'])\n",
|
|
|
+ " myfig['friction'].draw()"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 12,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "left = Button(\n",
|
|
|
+ " description = '',\n",
|
|
|
+ " icon = 'rotate-left',\n",
|
|
|
+ ")\n",
|
|
|
+ "left.on_click(doleft)\n",
|
|
|
+ "right = Button(\n",
|
|
|
+ " description = '',\n",
|
|
|
+ " icon = 'rotate-right',\n",
|
|
|
+ ")\n",
|
|
|
+ "right.on_click(doright)"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 13,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [
|
|
|
+ {
|
|
|
+ "data": {
|
|
|
+ "application/vnd.jupyter.widget-view+json": {
|
|
|
+ "model_id": "3cff8da2d92b4c4a803bac48e8f4a06f",
|
|
|
+ "version_major": 2,
|
|
|
+ "version_minor": 0
|
|
|
+ },
|
|
|
+ "text/plain": [
|
|
|
+ "AppLayout(children=(HBox(children=(Button(icon='rotate-left', style=ButtonStyle()), Button(icon='rotate-right'…"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ "metadata": {},
|
|
|
+ "output_type": "display_data"
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "source": [
|
|
|
+ "AppLayout(\n",
|
|
|
+ " center=drawing_tool.mpl.gcf().canvas,\n",
|
|
|
+ " footer=HBox([left,right]),\n",
|
|
|
+ " pane_heights=[0, 6, 1]\n",
|
|
|
+ ")\n",
|
|
|
+ "#drawing_tool.mpl.ion()"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 14,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "drawing_tool.mpl.ion()"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "myfig['friction'].graphviz_dot('friction')"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "!dot -Tpng -o friction.png friction.dot"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "markdown",
|
|
|
+ "metadata": {},
|
|
|
+ "source": [
|
|
|
+ ""
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "drawing_tool.mpl.gcf().canvas.print_png(\"friction.png\")"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "markdown",
|
|
|
+ "metadata": {},
|
|
|
+ "source": [
|
|
|
+ ""
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "display(SVG(sketch2SVG()))"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "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
|
|
|
+}
|