|
|
@@ -22,7 +22,7 @@
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
- "from ipywidgets import FloatSlider"
|
|
|
+ "from ipywidgets import FloatSlider, AppLayout, Label, HBox"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
|
@@ -40,8 +40,42 @@
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
- "from pysketcher import *\n",
|
|
|
- "\n",
|
|
|
+ "import time"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 5,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "from IPython.display import display, clear_output"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 6,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "from pysketcher import *"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 7,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "g = 9.81"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 8,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
"def inclined_plane():\n",
|
|
|
" theta = 30.\n",
|
|
|
" L = 10.\n",
|
|
|
@@ -94,8 +128,6 @@
|
|
|
"\n",
|
|
|
" drawing_tool.set_linecolor('black')\n",
|
|
|
" N = Force(contact - 2*r*normal_vec, contact, r'$N$', text_pos='start')\n",
|
|
|
- " V = Force(c, c + 0.001*tangent_vec, r'$V$', text_pos='end')\n",
|
|
|
- " V.set_linecolor('red')\n",
|
|
|
" mg = Gravity(c, 3*r, text='$Mg$')\n",
|
|
|
"\n",
|
|
|
" x_const = Line(contact, contact + point(0,4))\n",
|
|
|
@@ -107,7 +139,7 @@
|
|
|
"\n",
|
|
|
" body = Composition({'wheel': wheel, 'N': N, 'mg': mg})\n",
|
|
|
" fixed = Composition({'angle': angle, 'inclined wall': wall,\n",
|
|
|
- " 'wheel': wheel, 'V': V, 'ground': ground,\n",
|
|
|
+ " 'ground': ground,\n",
|
|
|
" 'x start': x_const, 'x axis': x_axis})\n",
|
|
|
"\n",
|
|
|
" fig = Composition({'body': body, 'fixed elements': fixed})\n",
|
|
|
@@ -117,31 +149,36 @@
|
|
|
"def position(t):\n",
|
|
|
" \"\"\"Position of center point of wheel.\"\"\"\n",
|
|
|
" global tangent_vec,c\n",
|
|
|
- " return c + 7*t**2*tangent_vec\n",
|
|
|
- "\n",
|
|
|
- "def speed(t):\n",
|
|
|
- " global tangent_vec\n",
|
|
|
- " return 0.14*t*tangent_vec \n",
|
|
|
+ " return c + 0.5*g*t**2*tangent_vec\n",
|
|
|
"\n",
|
|
|
"t = 0\n",
|
|
|
"\n",
|
|
|
+ "def speed(displacement,dt):\n",
|
|
|
+ " if dt != 0: \n",
|
|
|
+ " v = (displacement)/dt\n",
|
|
|
+ " #print(v)\n",
|
|
|
+ " v = numpy.sqrt(v[0]**2 + v[1]**2)\n",
|
|
|
+ " else:\n",
|
|
|
+ " v = 0\n",
|
|
|
+ " return v\n",
|
|
|
+ " \n",
|
|
|
"def move(change):\n",
|
|
|
- " global fig,t\n",
|
|
|
+ " global fig,t,label,x,x0,dt\n",
|
|
|
" dt = change.new - t \n",
|
|
|
" t = change.new\n",
|
|
|
" drawing_tool.erase()\n",
|
|
|
" x = position(t)\n",
|
|
|
" x0 = position(t-dt)\n",
|
|
|
- " displacement = x - x0\n",
|
|
|
- " fig['fixed elements']['V']['arrow']['line'] = Line(x,x+speed(t))\n",
|
|
|
+ " displacement = x - x0 \n",
|
|
|
" fig['body'].translate(displacement)\n",
|
|
|
" fig.draw()\n",
|
|
|
- " drawing_tool.display()"
|
|
|
+ " label.value = f\"v={speed(displacement,dt):.2f}\"\n",
|
|
|
+ " #drawing_tool.display()"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 5,
|
|
|
+ "execution_count": 9,
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
@@ -158,42 +195,27 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 6,
|
|
|
+ "execution_count": 10,
|
|
|
"metadata": {},
|
|
|
- "outputs": [
|
|
|
- {
|
|
|
- "data": {
|
|
|
- "application/vnd.jupyter.widget-view+json": {
|
|
|
- "model_id": "4c6c086038e241819081cf84d58d0331",
|
|
|
- "version_major": 2,
|
|
|
- "version_minor": 0
|
|
|
- },
|
|
|
- "text/plain": [
|
|
|
- "FloatSlider(value=0.0, description='Time:', max=1.0, step=0.03333333333333333)"
|
|
|
- ]
|
|
|
- },
|
|
|
- "metadata": {},
|
|
|
- "output_type": "display_data"
|
|
|
- }
|
|
|
- ],
|
|
|
+ "outputs": [],
|
|
|
"source": [
|
|
|
- "slider"
|
|
|
+ "label = Label(value=\"0\")"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 7,
|
|
|
+ "execution_count": 11,
|
|
|
"metadata": {},
|
|
|
"outputs": [
|
|
|
{
|
|
|
"data": {
|
|
|
"application/vnd.jupyter.widget-view+json": {
|
|
|
- "model_id": "1b7605e135de4e258d920e8c0da91831",
|
|
|
+ "model_id": "d62ee3eb721b4dfb8e5ed6cb5f0b506b",
|
|
|
"version_major": 2,
|
|
|
"version_minor": 0
|
|
|
},
|
|
|
"text/plain": [
|
|
|
- "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
|
|
|
+ "AppLayout(children=(HBox(children=(FloatSlider(value=0.0, description='Time:', max=1.0, step=0.033333333333333…"
|
|
|
]
|
|
|
},
|
|
|
"metadata": {},
|
|
|
@@ -201,43 +223,22 @@
|
|
|
}
|
|
|
],
|
|
|
"source": [
|
|
|
- "fig,normal_vec,tangent_vec,c = inclined_plane()"
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": null,
|
|
|
- "metadata": {},
|
|
|
- "outputs": [],
|
|
|
- "source": [
|
|
|
- "speed(0)"
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": null,
|
|
|
- "metadata": {},
|
|
|
- "outputs": [],
|
|
|
- "source": [
|
|
|
- "position(0)"
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": null,
|
|
|
- "metadata": {},
|
|
|
- "outputs": [],
|
|
|
- "source": [
|
|
|
- "fig['fixed elements']['V']['arrow']['line'].x"
|
|
|
+ "fig,normal_vec,tangent_vec,c = inclined_plane()\n",
|
|
|
+ "AppLayout(\n",
|
|
|
+ " center=drawing_tool.mpl.gcf().canvas,\n",
|
|
|
+ " footer=HBox([slider,label]),\n",
|
|
|
+ " pane_heights=[0, 6, 1]\n",
|
|
|
+ ")\n",
|
|
|
+ "#drawing_tool.mpl.ion()"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": null,
|
|
|
+ "execution_count": 12,
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
- "fig['fixed elements']['V']['arrow']['line'].y"
|
|
|
+ "drawing_tool.mpl.ion()"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
|
@@ -246,7 +247,10 @@
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
- "speed(0.3)"
|
|
|
+ "for t in numpy.linspace(0.0,1.0,100):\n",
|
|
|
+ " slider.value = t\n",
|
|
|
+ " print(t)\n",
|
|
|
+ " clear_output(wait=True)"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
|
@@ -255,16 +259,61 @@
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
- "t"
|
|
|
+ "drawing_tool.mpl.ioff()"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": null,
|
|
|
+ "execution_count": 14,
|
|
|
"metadata": {},
|
|
|
- "outputs": [],
|
|
|
+ "outputs": [
|
|
|
+ {
|
|
|
+ "data": {
|
|
|
+ "text/plain": [
|
|
|
+ "<bound method Shape.show_hierarchy of {\n",
|
|
|
+ "'body': {\n",
|
|
|
+ " 'wheel': {\n",
|
|
|
+ " 'outer': {\n",
|
|
|
+ " 'arc': \"181 (x,y) coords linecolor='b' fillcolor='b' fillpattern=''\",},\n",
|
|
|
+ " 'inner': {\n",
|
|
|
+ " 'arc': \"181 (x,y) coords linecolor='b' fillcolor='w' fillpattern=''\",},},\n",
|
|
|
+ " 'N': {\n",
|
|
|
+ " 'arrow': {\n",
|
|
|
+ " 'line': \"2 (x,y) coords arrow='->'\",},\n",
|
|
|
+ " 'text': \"Text at (2.7875,1.94134)\",},\n",
|
|
|
+ " 'mg': {\n",
|
|
|
+ " 'arrow': {\n",
|
|
|
+ " 'line': \"2 (x,y) coords linecolor='k' arrow='->'\",},\n",
|
|
|
+ " 'text': \"Text at (4.5,1.48248)\",},},\n",
|
|
|
+ "'fixed elements': {\n",
|
|
|
+ " 'angle': {\n",
|
|
|
+ " 'arc': {\n",
|
|
|
+ " 'arc': \"181 (x,y) coords linecolor='k' linewidth=1\",},\n",
|
|
|
+ " 'text': \"Text at (7.86074,0.841162)\",},\n",
|
|
|
+ " 'inclined wall': {\n",
|
|
|
+ " 'wall': \"4 (x,y) coords fillcolor='white' fillpattern='/'\",},\n",
|
|
|
+ " 'ground': {\n",
|
|
|
+ " 'line': \"2 (x,y) coords linecolor='k' linewidth=1 linestyle='dashed'\",},\n",
|
|
|
+ " 'x start': {\n",
|
|
|
+ " 'line': \"2 (x,y) coords linestyle='dotted'\",},\n",
|
|
|
+ " 'x axis': {\n",
|
|
|
+ " 'arrow': {\n",
|
|
|
+ " 'line': {\n",
|
|
|
+ " 'line': \"2 (x,y) coords\",},\n",
|
|
|
+ " 'head left': {\n",
|
|
|
+ " 'line': \"2 (x,y) coords linestyle='solid'\",},\n",
|
|
|
+ " 'head right': {\n",
|
|
|
+ " 'line': \"2 (x,y) coords linestyle='solid'\",},},\n",
|
|
|
+ " 'label': \"Text at (9.25278,4.47286)\",},},}>"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ "execution_count": 14,
|
|
|
+ "metadata": {},
|
|
|
+ "output_type": "execute_result"
|
|
|
+ }
|
|
|
+ ],
|
|
|
"source": [
|
|
|
- "position(t)"
|
|
|
+ "fig.show_hierarchy"
|
|
|
]
|
|
|
},
|
|
|
{
|