Selaa lähdekoodia

solved the angle issue

Gilbert Brault 5 vuotta sitten
vanhempi
commit
aaa07cae56

+ 111 - 24
notebooks/.ipynb_checkpoints/DryFriction-checkpoint.ipynb

@@ -135,21 +135,20 @@
     "    style:\n",
     "        linecolor: blue\n",
     "        filled_curves: blue\n",
-    "    transform: [\"rotate(-theta, contact)\",\"translate(-rl/2*tangent_vec)\"]\n",
+    "    transform: [\"rotate(-theta, contact)\",\n",
+    "                \"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",
+    "mc:\n",
+    "    formula: Text(r'$c$', c)\n",
     "body: \n",
-    "    formula: \"Composition({'wheel': wheel, 'N': N, 'mg': mg})\"\n",
+    "    formula: \"Composition({'wheel': wheel, 'N': N, 'mc': mc})\"\n",
     "    style:\n",
     "        linecolor: black\n",
     "mB:\n",
@@ -160,6 +159,19 @@
     "    formula: Wall(x=[A[0], B[0]], y=[A[1], B[1]], thickness=-0.25,transparent=False)\n",
     "    style:\n",
     "        linecolor: black    \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, 'inclined wall': wall, 'x start': x_const, 'x axis': x_axis, 'mA': mA, 'mB': mB})\"\n",
+    "mg: \n",
+    "    formula: Gravity(c, rl, text='$Mg$')\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",
@@ -171,17 +183,8 @@
     "         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",
+    "    formula: \"Composition({'plan': plan, 'ground': ground, 'mg': mg, 'angle': angle})\"\n",
     "\"\"\""
    ]
   },
@@ -225,20 +228,23 @@
    "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",
+    "    angle = myfig['theta']\n",
+    "    angle -= theta\n",
+    "    myfig['theta'] = angle\n",
     "    drawing_tool.erase()\n",
-    "    myfig['plan']['angle'].changeAngles(180-angle,angle)\n",
+    "    x = myfig['plan']['body']['mc'].x\n",
+    "    y = myfig['plan']['body']['mc'].y\n",
     "    myfig['plan'].rotate(theta,myfig['B'])\n",
+    "    xf = myfig['plan']['body']['mc'].x\n",
+    "    yf = myfig['plan']['body']['mc'].y\n",
+    "    trans = point(xf-x,yf-y)\n",
+    "    myfig['angle'].changeAngle(180-angle, angle)\n",
+    "    myfig['mg'].translate(trans)\n",
     "    myfig['friction'].draw()"
    ]
   },
@@ -283,7 +289,7 @@
     {
      "data": {
       "application/vnd.jupyter.widget-view+json": {
-       "model_id": "83e8b7e739ef4b3c95a755a92d105b51",
+       "model_id": "7353158e16224023a1a98fc5f4fd2830",
        "version_major": 2,
        "version_minor": 0
       },
@@ -333,6 +339,87 @@
     "Use left and right rotation button to rotate the sketch"
    ]
   },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "angle = myfig['theta']"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "angle"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "myfig['plan']['angle'].changeAngle(angle)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "myfig['plan']['angle']['arc'].arc_angle *180 /3.14"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "myfig['plan']['angle']['arc'].start_angle  *180 /3.14"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    " myfig['theta']"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "myfig['plan']['angle'].radius"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "myfig['plan']['angle'].center"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "myfig['plan']['angle'].resolution"
+   ]
+  },
   {
    "cell_type": "markdown",
    "metadata": {},

+ 109 - 23
notebooks/DryFriction.ipynb

@@ -141,16 +141,14 @@
     "    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",
+    "mc:\n",
+    "    formula: Text(r'$c$', c)\n",
     "body: \n",
-    "    formula: \"Composition({'wheel': wheel, 'N': N, 'mg': mg})\"\n",
+    "    formula: \"Composition({'wheel': wheel, 'N': N, 'mc': mc})\"\n",
     "    style:\n",
     "        linecolor: black\n",
     "mB:\n",
@@ -161,6 +159,19 @@
     "    formula: Wall(x=[A[0], B[0]], y=[A[1], B[1]], thickness=-0.25,transparent=False)\n",
     "    style:\n",
     "        linecolor: black    \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, 'inclined wall': wall, 'x start': x_const, 'x axis': x_axis, 'mA': mA, 'mB': mB})\"\n",
+    "mg: \n",
+    "    formula: Gravity(c, rl, text='$Mg$')\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",
@@ -172,17 +183,8 @@
     "         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",
+    "    formula: \"Composition({'plan': plan, 'ground': ground, 'mg': mg, 'angle': angle})\"\n",
     "\"\"\""
    ]
   },
@@ -226,20 +228,23 @@
    "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",
+    "    angle = myfig['theta']\n",
+    "    angle -= theta\n",
+    "    myfig['theta'] = angle\n",
     "    drawing_tool.erase()\n",
-    "    myfig['plan']['angle'].changeAngles(180-angle,angle)\n",
+    "    x = myfig['plan']['body']['mc'].x\n",
+    "    y = myfig['plan']['body']['mc'].y\n",
     "    myfig['plan'].rotate(theta,myfig['B'])\n",
+    "    xf = myfig['plan']['body']['mc'].x\n",
+    "    yf = myfig['plan']['body']['mc'].y\n",
+    "    trans = point(xf-x,yf-y)\n",
+    "    myfig['angle'].changeAngle(180-angle, angle)\n",
+    "    myfig['mg'].translate(trans)\n",
     "    myfig['friction'].draw()"
    ]
   },
@@ -284,7 +289,7 @@
     {
      "data": {
       "application/vnd.jupyter.widget-view+json": {
-       "model_id": "cce2ada706774056b97b0cf67115a55c",
+       "model_id": "7353158e16224023a1a98fc5f4fd2830",
        "version_major": 2,
        "version_minor": 0
       },
@@ -334,6 +339,87 @@
     "Use left and right rotation button to rotate the sketch"
    ]
   },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "angle = myfig['theta']"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "angle"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "myfig['plan']['angle'].changeAngle(angle)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "myfig['plan']['angle']['arc'].arc_angle *180 /3.14"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "myfig['plan']['angle']['arc'].start_angle  *180 /3.14"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    " myfig['theta']"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "myfig['plan']['angle'].radius"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "myfig['plan']['angle'].center"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "myfig['plan']['angle'].resolution"
+   ]
+  },
   {
    "cell_type": "markdown",
    "metadata": {},

+ 16 - 7
pysketcher/shapes.py

@@ -1105,12 +1105,15 @@ class Arc(Shape):
         self.radius = radius
         self.start_angle = radians(start_angle)
         self.arc_angle = radians(arc_angle)
+        self.resolution = resolution
+        self.setCurve()
 
+    def setCurve(self):
         t = linspace(self.start_angle,
                      self.start_angle + self.arc_angle,
-                     resolution+1)
-        x0 = center[0];  y0 = center[1]
-        R = radius
+                     self.resolution+1)
+        x0 = self.center[0];  y0 = self.center[1]
+        R = self.radius
         x = x0 + R*cos(t)
         y = y0 + R*sin(t)
         self.shapes = {'arc': Curve(x, y)}
@@ -1644,17 +1647,23 @@ class Arc_wText(Shape):
         self.fontsize=fontsize
         self.resolution=resolution
         self.text_spacing=text_spacing
-        self.changeAngles(start_angle,arc_angle)
-    def changeAngles(self,start_angle,arc_angle):
-        arc = Arc(self.center, self.radius, start_angle, arc_angle,
+        self.start_angle = start_angle
+        self.arc_angle = arc_angle
+        self.setArc()
+    def setArc(self):
+        arc = Arc(self.center, self.radius, self.start_angle, self.arc_angle,
                   self.resolution)
-        mid = arr2D(arc(arc_angle/2.))
+        mid = arr2D(arc(self.arc_angle/2.))
         normal = unit_vec(mid - arr2D(self.center))
         text_pos = mid + normal*drawing_tool.xrange*self.text_spacing
         if hasattr(self, 'linewidth'):
             arc.set_linewidth(self.linewidth)
         self.shapes = {'arc': arc,
                        'text': Text(self.text, text_pos, fontsize=self.fontsize)}
+    def changeAngle(self,start_angle,arc_angle):
+        self.arc_angle = arc_angle
+        self.start_angle = start_angle
+        self.setArc()
     def set_linewidth(self, width):
         self.linewidth = width
         self.change_linewidth()