Hans Petter Langtangen 10 years ago
parent
commit
613ef3eafa

+ 1 - 1
doc/pub/tutorial/._pysketcher000.html

@@ -175,7 +175,7 @@ MathJax.Hub.Config({
 <center>[2] <b>Department of Informatics, University of Oslo</b></center>
 <center>[2] <b>Department of Informatics, University of Oslo</b></center>
 <br>
 <br>
 <p>
 <p>
-<center><h4>Dec 22, 2015</h4></center> <!-- date -->
+<center><h4>Dec 23, 2015</h4></center> <!-- date -->
 <br>
 <br>
 <p>
 <p>
 
 

+ 20 - 20
doc/pub/tutorial/._pysketcher003.html

@@ -262,9 +262,9 @@ was produced by this code:
         <span style="color: #BA2121">&#39;a2&#39;</span>: Distance_wText((<span style="color: #666666">0</span>,<span style="color: #666666">2</span>), (<span style="color: #666666">2</span>, <span style="color: #666666">0</span>), t, fontsize),
         <span style="color: #BA2121">&#39;a2&#39;</span>: Distance_wText((<span style="color: #666666">0</span>,<span style="color: #666666">2</span>), (<span style="color: #666666">2</span>, <span style="color: #666666">0</span>), t, fontsize),
         <span style="color: #BA2121">&#39;a3&#39;</span>: Distance_wText((<span style="color: #666666">2</span>,<span style="color: #666666">4.5</span>), (<span style="color: #666666">0</span>, <span style="color: #666666">5.5</span>), t, fontsize),
         <span style="color: #BA2121">&#39;a3&#39;</span>: Distance_wText((<span style="color: #666666">2</span>,<span style="color: #666666">4.5</span>), (<span style="color: #666666">0</span>, <span style="color: #666666">5.5</span>), t, fontsize),
         <span style="color: #BA2121">&#39;a4&#39;</span>: Distance_wText((<span style="color: #666666">8</span>,<span style="color: #666666">4</span>), (<span style="color: #666666">10</span>, <span style="color: #666666">3</span>), t, fontsize,
         <span style="color: #BA2121">&#39;a4&#39;</span>: Distance_wText((<span style="color: #666666">8</span>,<span style="color: #666666">4</span>), (<span style="color: #666666">10</span>, <span style="color: #666666">3</span>), t, fontsize,
-                             text_spacing<span style="color: #666666">=</span>old_div(<span style="color: #666666">-1.</span>,<span style="color: #666666">60</span>)),
+                             text_spacing<span style="color: #666666">=-1./60</span>),
         <span style="color: #BA2121">&#39;a5&#39;</span>: Distance_wText((<span style="color: #666666">8</span>,<span style="color: #666666">2</span>), (<span style="color: #666666">10</span>, <span style="color: #666666">1</span>), t, fontsize,
         <span style="color: #BA2121">&#39;a5&#39;</span>: Distance_wText((<span style="color: #666666">8</span>,<span style="color: #666666">2</span>), (<span style="color: #666666">10</span>, <span style="color: #666666">1</span>), t, fontsize,
-                             text_spacing<span style="color: #666666">=</span>old_div(<span style="color: #666666">-1.</span>,<span style="color: #666666">40</span>), alignment<span style="color: #666666">=</span><span style="color: #BA2121">&#39;right&#39;</span>),
+                             text_spacing<span style="color: #666666">=-1./40</span>, alignment<span style="color: #666666">=</span><span style="color: #BA2121">&#39;right&#39;</span>),
         <span style="color: #BA2121">&#39;c1&#39;</span>: Text_wArrow(<span style="color: #BA2121">&#39;text_spacing=-1./60&#39;</span>,
         <span style="color: #BA2121">&#39;c1&#39;</span>: Text_wArrow(<span style="color: #BA2121">&#39;text_spacing=-1./60&#39;</span>,
                           (<span style="color: #666666">4</span>, <span style="color: #666666">3.5</span>), (<span style="color: #666666">9</span>, <span style="color: #666666">3.2</span>),
                           (<span style="color: #666666">4</span>, <span style="color: #666666">3.5</span>), (<span style="color: #666666">9</span>, <span style="color: #666666">3.2</span>),
                           fontsize<span style="color: #666666">=10</span>, alignment<span style="color: #666666">=</span><span style="color: #BA2121">&#39;left&#39;</span>),
                           fontsize<span style="color: #666666">=10</span>, alignment<span style="color: #666666">=</span><span style="color: #BA2121">&#39;left&#39;</span>),
@@ -301,12 +301,12 @@ The above figure can be produced by the following code.
     W <span style="color: #666666">=</span> <span style="color: #666666">4.0</span>
     W <span style="color: #666666">=</span> <span style="color: #666666">4.0</span>
 
 
     drawing_tool<span style="color: #666666">.</span>set_coordinate_system(
     drawing_tool<span style="color: #666666">.</span>set_coordinate_system(
-        xmin<span style="color: #666666">=0</span>, xmax<span style="color: #666666">=2*</span>W, ymin<span style="color: #666666">=</span>old_div(<span style="color: #666666">-</span>L,<span style="color: #666666">2</span>), ymax<span style="color: #666666">=2*</span>L,
+        xmin<span style="color: #666666">=0</span>, xmax<span style="color: #666666">=2*</span>W, ymin<span style="color: #666666">=-</span>L<span style="color: #666666">/2</span>, ymax<span style="color: #666666">=2*</span>L,
         axis<span style="color: #666666">=</span><span style="color: #008000">True</span>, instruction_file<span style="color: #666666">=</span><span style="color: #BA2121">&#39;tmp_Rectangle.py&#39;</span>)
         axis<span style="color: #666666">=</span><span style="color: #008000">True</span>, instruction_file<span style="color: #666666">=</span><span style="color: #BA2121">&#39;tmp_Rectangle.py&#39;</span>)
     drawing_tool<span style="color: #666666">.</span>set_linecolor(<span style="color: #BA2121">&#39;blue&#39;</span>)
     drawing_tool<span style="color: #666666">.</span>set_linecolor(<span style="color: #BA2121">&#39;blue&#39;</span>)
     drawing_tool<span style="color: #666666">.</span>set_grid(<span style="color: #008000">True</span>)
     drawing_tool<span style="color: #666666">.</span>set_grid(<span style="color: #008000">True</span>)
 
 
-    xpos <span style="color: #666666">=</span> old_div(W,<span style="color: #666666">2</span>)
+    xpos <span style="color: #666666">=</span> W<span style="color: #666666">/2</span>
     r <span style="color: #666666">=</span> Rectangle(lower_left_corner<span style="color: #666666">=</span>(xpos,<span style="color: #666666">0</span>), width<span style="color: #666666">=</span>W, height<span style="color: #666666">=</span>L)
     r <span style="color: #666666">=</span> Rectangle(lower_left_corner<span style="color: #666666">=</span>(xpos,<span style="color: #666666">0</span>), width<span style="color: #666666">=</span>W, height<span style="color: #666666">=</span>L)
     r<span style="color: #666666">.</span>draw()
     r<span style="color: #666666">.</span>draw()
     r<span style="color: #666666">.</span>draw_dimensions()
     r<span style="color: #666666">.</span>draw_dimensions()
@@ -337,13 +337,13 @@ The code below produces the figure.
     W <span style="color: #666666">=</span> <span style="color: #666666">4.0</span>
     W <span style="color: #666666">=</span> <span style="color: #666666">4.0</span>
 
 
     drawing_tool<span style="color: #666666">.</span>set_coordinate_system(
     drawing_tool<span style="color: #666666">.</span>set_coordinate_system(
-        xmin<span style="color: #666666">=0</span>, xmax<span style="color: #666666">=2*</span>W, ymin<span style="color: #666666">=</span>old_div(<span style="color: #666666">-</span>L,<span style="color: #666666">2</span>), ymax<span style="color: #666666">=1.2*</span>L,
+        xmin<span style="color: #666666">=0</span>, xmax<span style="color: #666666">=2*</span>W, ymin<span style="color: #666666">=-</span>L<span style="color: #666666">/2</span>, ymax<span style="color: #666666">=1.2*</span>L,
         axis<span style="color: #666666">=</span><span style="color: #008000">True</span>, instruction_file<span style="color: #666666">=</span><span style="color: #BA2121">&#39;tmp_Triangle.py&#39;</span>)
         axis<span style="color: #666666">=</span><span style="color: #008000">True</span>, instruction_file<span style="color: #666666">=</span><span style="color: #BA2121">&#39;tmp_Triangle.py&#39;</span>)
     drawing_tool<span style="color: #666666">.</span>set_linecolor(<span style="color: #BA2121">&#39;blue&#39;</span>)
     drawing_tool<span style="color: #666666">.</span>set_linecolor(<span style="color: #BA2121">&#39;blue&#39;</span>)
     drawing_tool<span style="color: #666666">.</span>set_grid(<span style="color: #008000">True</span>)
     drawing_tool<span style="color: #666666">.</span>set_grid(<span style="color: #008000">True</span>)
 
 
     xpos <span style="color: #666666">=</span> <span style="color: #666666">1</span>
     xpos <span style="color: #666666">=</span> <span style="color: #666666">1</span>
-    t <span style="color: #666666">=</span> Triangle(p1<span style="color: #666666">=</span>(old_div(W,<span style="color: #666666">2</span>),<span style="color: #666666">0</span>), p2<span style="color: #666666">=</span>(<span style="color: #666666">3*</span>W<span style="color: #666666">/2</span>,old_div(W,<span style="color: #666666">2</span>)), p3<span style="color: #666666">=</span>(<span style="color: #666666">4*</span>W<span style="color: #666666">/5.</span>,L))
+    t <span style="color: #666666">=</span> Triangle(p1<span style="color: #666666">=</span>(W<span style="color: #666666">/2</span>,<span style="color: #666666">0</span>), p2<span style="color: #666666">=</span>(<span style="color: #666666">3*</span>W<span style="color: #666666">/2</span>,W<span style="color: #666666">/2</span>), p3<span style="color: #666666">=</span>(<span style="color: #666666">4*</span>W<span style="color: #666666">/5.</span>,L))
     t<span style="color: #666666">.</span>draw()
     t<span style="color: #666666">.</span>draw()
     t<span style="color: #666666">.</span>draw_dimensions()
     t<span style="color: #666666">.</span>draw_dimensions()
     drawing_tool<span style="color: #666666">.</span>display(<span style="color: #BA2121">&#39;Triangle&#39;</span>)
     drawing_tool<span style="color: #666666">.</span>display(<span style="color: #BA2121">&#39;Triangle&#39;</span>)
@@ -374,13 +374,13 @@ An arc like the one above is produced by
     W <span style="color: #666666">=</span> <span style="color: #666666">4.0</span>
     W <span style="color: #666666">=</span> <span style="color: #666666">4.0</span>
 
 
     drawing_tool<span style="color: #666666">.</span>set_coordinate_system(
     drawing_tool<span style="color: #666666">.</span>set_coordinate_system(
-        xmin<span style="color: #666666">=</span>old_div(<span style="color: #666666">-</span>W,<span style="color: #666666">2</span>), xmax<span style="color: #666666">=</span>W, ymin<span style="color: #666666">=</span>old_div(<span style="color: #666666">-</span>L,<span style="color: #666666">2</span>), ymax<span style="color: #666666">=1.5*</span>L,
+        xmin<span style="color: #666666">=-</span>W<span style="color: #666666">/2</span>, xmax<span style="color: #666666">=</span>W, ymin<span style="color: #666666">=-</span>L<span style="color: #666666">/2</span>, ymax<span style="color: #666666">=1.5*</span>L,
         axis<span style="color: #666666">=</span><span style="color: #008000">True</span>, instruction_file<span style="color: #666666">=</span><span style="color: #BA2121">&#39;tmp_Arc.py&#39;</span>)
         axis<span style="color: #666666">=</span><span style="color: #008000">True</span>, instruction_file<span style="color: #666666">=</span><span style="color: #BA2121">&#39;tmp_Arc.py&#39;</span>)
     drawing_tool<span style="color: #666666">.</span>set_linecolor(<span style="color: #BA2121">&#39;blue&#39;</span>)
     drawing_tool<span style="color: #666666">.</span>set_linecolor(<span style="color: #BA2121">&#39;blue&#39;</span>)
     drawing_tool<span style="color: #666666">.</span>set_grid(<span style="color: #008000">True</span>)
     drawing_tool<span style="color: #666666">.</span>set_grid(<span style="color: #008000">True</span>)
 
 
     center <span style="color: #666666">=</span> point(<span style="color: #666666">0</span>,<span style="color: #666666">0</span>)
     center <span style="color: #666666">=</span> point(<span style="color: #666666">0</span>,<span style="color: #666666">0</span>)
-    radius <span style="color: #666666">=</span> old_div(L,<span style="color: #666666">2</span>)
+    radius <span style="color: #666666">=</span> L<span style="color: #666666">/2</span>
     start_angle <span style="color: #666666">=</span> <span style="color: #666666">60</span>
     start_angle <span style="color: #666666">=</span> <span style="color: #666666">60</span>
     arc_angle <span style="color: #666666">=</span> <span style="color: #666666">45</span>
     arc_angle <span style="color: #666666">=</span> <span style="color: #666666">45</span>
     a <span style="color: #666666">=</span> Arc(center, radius, start_angle, arc_angle)
     a <span style="color: #666666">=</span> Arc(center, radius, start_angle, arc_angle)
@@ -393,11 +393,11 @@ An arc like the one above is produced by
         <span style="color: #BA2121">&#39;start_angle&#39;</span>:
         <span style="color: #BA2121">&#39;start_angle&#39;</span>:
         Arc_wText(
         Arc_wText(
             <span style="color: #BA2121">&#39;start_angle&#39;</span>, center, R1, start_angle<span style="color: #666666">=0</span>,
             <span style="color: #BA2121">&#39;start_angle&#39;</span>, center, R1, start_angle<span style="color: #666666">=0</span>,
-            arc_angle<span style="color: #666666">=</span>start_angle, text_spacing<span style="color: #666666">=</span>old_div(<span style="color: #666666">1</span>,<span style="color: #666666">10.</span>)),
+            arc_angle<span style="color: #666666">=</span>start_angle, text_spacing<span style="color: #666666">=1/10.</span>),
         <span style="color: #BA2121">&#39;arc_angle&#39;</span>:
         <span style="color: #BA2121">&#39;arc_angle&#39;</span>:
         Arc_wText(
         Arc_wText(
             <span style="color: #BA2121">&#39;arc_angle&#39;</span>, center, R2, start_angle<span style="color: #666666">=</span>start_angle,
             <span style="color: #BA2121">&#39;arc_angle&#39;</span>, center, R2, start_angle<span style="color: #666666">=</span>start_angle,
-            arc_angle<span style="color: #666666">=</span>arc_angle, text_spacing<span style="color: #666666">=</span>old_div(<span style="color: #666666">1</span>,<span style="color: #666666">20.</span>)),
+            arc_angle<span style="color: #666666">=</span>arc_angle, text_spacing<span style="color: #666666">=1/20.</span>),
         <span style="color: #BA2121">&#39;r=0&#39;</span>:
         <span style="color: #BA2121">&#39;r=0&#39;</span>:
         Line(center, center <span style="color: #666666">+</span>
         Line(center, center <span style="color: #666666">+</span>
              point(R<span style="color: #666666">*</span>cos(radians(start_angle)),
              point(R<span style="color: #666666">*</span>cos(radians(start_angle)),
@@ -409,8 +409,8 @@ An arc like the one above is produced by
         <span style="color: #BA2121">&#39;r=start+arc_angle&#39;</span>:
         <span style="color: #BA2121">&#39;r=start+arc_angle&#39;</span>:
         Line(center, center <span style="color: #666666">+</span>
         Line(center, center <span style="color: #666666">+</span>
              point(R, <span style="color: #666666">0</span>))<span style="color: #666666">.</span>set_linestyle(<span style="color: #BA2121">&#39;dashed&#39;</span>),
              point(R, <span style="color: #666666">0</span>))<span style="color: #666666">.</span>set_linestyle(<span style="color: #BA2121">&#39;dashed&#39;</span>),
-        <span style="color: #BA2121">&#39;radius&#39;</span>: Distance_wText(center, a(<span style="color: #666666">0</span>), <span style="color: #BA2121">&#39;radius&#39;</span>, text_spacing<span style="color: #666666">=</span>old_div(<span style="color: #666666">1</span>,<span style="color: #666666">40.</span>)),
-        <span style="color: #BA2121">&#39;center&#39;</span>: Text(<span style="color: #BA2121">&#39;center&#39;</span>, center<span style="color: #666666">-</span>point(old_div(radius,<span style="color: #666666">10.</span>), old_div(radius,<span style="color: #666666">10.</span>))),
+        <span style="color: #BA2121">&#39;radius&#39;</span>: Distance_wText(center, a(<span style="color: #666666">0</span>), <span style="color: #BA2121">&#39;radius&#39;</span>, text_spacing<span style="color: #666666">=1/40.</span>),
+        <span style="color: #BA2121">&#39;center&#39;</span>: Text(<span style="color: #BA2121">&#39;center&#39;</span>, center<span style="color: #666666">-</span>point(radius<span style="color: #666666">/10.</span>, radius<span style="color: #666666">/10.</span>)),
         }
         }
     <span style="color: #008000; font-weight: bold">for</span> dimension <span style="color: #AA22FF; font-weight: bold">in</span> a<span style="color: #666666">.</span>dimensions:
     <span style="color: #008000; font-weight: bold">for</span> dimension <span style="color: #AA22FF; font-weight: bold">in</span> a<span style="color: #666666">.</span>dimensions:
         <span style="color: #008000; font-weight: bold">if</span> dimension<span style="color: #666666">.</span>startswith(<span style="color: #BA2121">&#39;r=&#39;</span>):
         <span style="color: #008000; font-weight: bold">if</span> dimension<span style="color: #666666">.</span>startswith(<span style="color: #BA2121">&#39;r=&#39;</span>):
@@ -443,7 +443,7 @@ The code for making these two springs goes like this:
     W <span style="color: #666666">=</span> <span style="color: #666666">2.0</span>
     W <span style="color: #666666">=</span> <span style="color: #666666">2.0</span>
 
 
     drawing_tool<span style="color: #666666">.</span>set_coordinate_system(
     drawing_tool<span style="color: #666666">.</span>set_coordinate_system(
-        xmin<span style="color: #666666">=0</span>, xmax<span style="color: #666666">=7*</span>W, ymin<span style="color: #666666">=</span>old_div(<span style="color: #666666">-</span>L,<span style="color: #666666">2</span>), ymax<span style="color: #666666">=1.5*</span>L,
+        xmin<span style="color: #666666">=0</span>, xmax<span style="color: #666666">=7*</span>W, ymin<span style="color: #666666">=-</span>L<span style="color: #666666">/2</span>, ymax<span style="color: #666666">=1.5*</span>L,
         axis<span style="color: #666666">=</span><span style="color: #008000">True</span>, instruction_file<span style="color: #666666">=</span><span style="color: #BA2121">&#39;tmp_Spring.py&#39;</span>)
         axis<span style="color: #666666">=</span><span style="color: #008000">True</span>, instruction_file<span style="color: #666666">=</span><span style="color: #BA2121">&#39;tmp_Spring.py&#39;</span>)
     drawing_tool<span style="color: #666666">.</span>set_linecolor(<span style="color: #BA2121">&#39;blue&#39;</span>)
     drawing_tool<span style="color: #666666">.</span>set_linecolor(<span style="color: #BA2121">&#39;blue&#39;</span>)
     drawing_tool<span style="color: #666666">.</span>set_grid(<span style="color: #008000">True</span>)
     drawing_tool<span style="color: #666666">.</span>set_grid(<span style="color: #008000">True</span>)
@@ -451,13 +451,13 @@ The code for making these two springs goes like this:
     xpos <span style="color: #666666">=</span> W
     xpos <span style="color: #666666">=</span> W
     s1 <span style="color: #666666">=</span> Spring((W,<span style="color: #666666">0</span>), L, teeth<span style="color: #666666">=</span><span style="color: #008000">True</span>)
     s1 <span style="color: #666666">=</span> Spring((W,<span style="color: #666666">0</span>), L, teeth<span style="color: #666666">=</span><span style="color: #008000">True</span>)
     s1_title <span style="color: #666666">=</span> Text(<span style="color: #BA2121">&#39;Default Spring&#39;</span>,
     s1_title <span style="color: #666666">=</span> Text(<span style="color: #BA2121">&#39;Default Spring&#39;</span>,
-                    s1<span style="color: #666666">.</span>geometric_features()[<span style="color: #BA2121">&#39;end&#39;</span>] <span style="color: #666666">+</span> point(<span style="color: #666666">0</span>,old_div(L,<span style="color: #666666">10</span>)))
+                    s1<span style="color: #666666">.</span>geometric_features()[<span style="color: #BA2121">&#39;end&#39;</span>] <span style="color: #666666">+</span> point(<span style="color: #666666">0</span>,L<span style="color: #666666">/10</span>))
     s1<span style="color: #666666">.</span>draw()
     s1<span style="color: #666666">.</span>draw()
     s1_title<span style="color: #666666">.</span>draw()
     s1_title<span style="color: #666666">.</span>draw()
     <span style="color: #408080; font-style: italic">#s1.draw_dimensions()</span>
     <span style="color: #408080; font-style: italic">#s1.draw_dimensions()</span>
     xpos <span style="color: #666666">+=</span> <span style="color: #666666">3*</span>W
     xpos <span style="color: #666666">+=</span> <span style="color: #666666">3*</span>W
-    s2 <span style="color: #666666">=</span> Spring(start<span style="color: #666666">=</span>(xpos,<span style="color: #666666">0</span>), length<span style="color: #666666">=</span>L, width<span style="color: #666666">=</span>old_div(W,<span style="color: #666666">2.</span>),
-                bar_length<span style="color: #666666">=</span>old_div(L,<span style="color: #666666">6.</span>), teeth<span style="color: #666666">=</span><span style="color: #008000">False</span>)
+    s2 <span style="color: #666666">=</span> Spring(start<span style="color: #666666">=</span>(xpos,<span style="color: #666666">0</span>), length<span style="color: #666666">=</span>L, width<span style="color: #666666">=</span>W<span style="color: #666666">/2.</span>,
+                bar_length<span style="color: #666666">=</span>L<span style="color: #666666">/6.</span>, teeth<span style="color: #666666">=</span><span style="color: #008000">False</span>)
     s2<span style="color: #666666">.</span>draw()
     s2<span style="color: #666666">.</span>draw()
     s2<span style="color: #666666">.</span>draw_dimensions()
     s2<span style="color: #666666">.</span>draw_dimensions()
     drawing_tool<span style="color: #666666">.</span>display(<span style="color: #BA2121">&#39;Spring&#39;</span>)
     drawing_tool<span style="color: #666666">.</span>display(<span style="color: #BA2121">&#39;Spring&#39;</span>)
@@ -484,7 +484,7 @@ This dashpot is produced by
     xpos <span style="color: #666666">=</span> <span style="color: #666666">0</span>
     xpos <span style="color: #666666">=</span> <span style="color: #666666">0</span>
 
 
     drawing_tool<span style="color: #666666">.</span>set_coordinate_system(
     drawing_tool<span style="color: #666666">.</span>set_coordinate_system(
-        xmin<span style="color: #666666">=</span>xpos, xmax<span style="color: #666666">=</span>xpos<span style="color: #666666">+5.5*</span>W, ymin<span style="color: #666666">=</span>old_div(<span style="color: #666666">-</span>L,<span style="color: #666666">2</span>), ymax<span style="color: #666666">=1.5*</span>L,
+        xmin<span style="color: #666666">=</span>xpos, xmax<span style="color: #666666">=</span>xpos<span style="color: #666666">+5.5*</span>W, ymin<span style="color: #666666">=-</span>L<span style="color: #666666">/2</span>, ymax<span style="color: #666666">=1.5*</span>L,
         axis<span style="color: #666666">=</span><span style="color: #008000">True</span>, instruction_file<span style="color: #666666">=</span><span style="color: #BA2121">&#39;tmp_Dashpot.py&#39;</span>)
         axis<span style="color: #666666">=</span><span style="color: #008000">True</span>, instruction_file<span style="color: #666666">=</span><span style="color: #BA2121">&#39;tmp_Dashpot.py&#39;</span>)
     drawing_tool<span style="color: #666666">.</span>set_linecolor(<span style="color: #BA2121">&#39;blue&#39;</span>)
     drawing_tool<span style="color: #666666">.</span>set_linecolor(<span style="color: #BA2121">&#39;blue&#39;</span>)
     drawing_tool<span style="color: #666666">.</span>set_grid(<span style="color: #008000">True</span>)
     drawing_tool<span style="color: #666666">.</span>set_grid(<span style="color: #008000">True</span>)
@@ -493,15 +493,15 @@ This dashpot is produced by
     xpos <span style="color: #666666">=</span> <span style="color: #666666">1.5</span>
     xpos <span style="color: #666666">=</span> <span style="color: #666666">1.5</span>
     d1 <span style="color: #666666">=</span> Dashpot(start<span style="color: #666666">=</span>(xpos,<span style="color: #666666">0</span>), total_length<span style="color: #666666">=</span>L)
     d1 <span style="color: #666666">=</span> Dashpot(start<span style="color: #666666">=</span>(xpos,<span style="color: #666666">0</span>), total_length<span style="color: #666666">=</span>L)
     d1_title <span style="color: #666666">=</span> Text(<span style="color: #BA2121">&#39;Dashpot (default)&#39;</span>,
     d1_title <span style="color: #666666">=</span> Text(<span style="color: #BA2121">&#39;Dashpot (default)&#39;</span>,
-                    d1<span style="color: #666666">.</span>geometric_features()[<span style="color: #BA2121">&#39;end&#39;</span>] <span style="color: #666666">+</span> point(<span style="color: #666666">0</span>,old_div(L,<span style="color: #666666">10</span>)))
+                    d1<span style="color: #666666">.</span>geometric_features()[<span style="color: #BA2121">&#39;end&#39;</span>] <span style="color: #666666">+</span> point(<span style="color: #666666">0</span>,L<span style="color: #666666">/10</span>))
     d1<span style="color: #666666">.</span>draw()
     d1<span style="color: #666666">.</span>draw()
     d1_title<span style="color: #666666">.</span>draw()
     d1_title<span style="color: #666666">.</span>draw()
 
 
     <span style="color: #408080; font-style: italic"># Dashpot for animation with fixed bar_length, dashpot_length and</span>
     <span style="color: #408080; font-style: italic"># Dashpot for animation with fixed bar_length, dashpot_length and</span>
     <span style="color: #408080; font-style: italic"># prescribed piston_pos</span>
     <span style="color: #408080; font-style: italic"># prescribed piston_pos</span>
     xpos <span style="color: #666666">+=</span> <span style="color: #666666">2.5*</span>W
     xpos <span style="color: #666666">+=</span> <span style="color: #666666">2.5*</span>W
-    d2 <span style="color: #666666">=</span> Dashpot(start<span style="color: #666666">=</span>(xpos,<span style="color: #666666">0</span>), total_length<span style="color: #666666">=1.2*</span>L, width<span style="color: #666666">=</span>old_div(W,<span style="color: #666666">2</span>),
-                 bar_length<span style="color: #666666">=</span>W, dashpot_length<span style="color: #666666">=</span>old_div(L,<span style="color: #666666">2</span>), piston_pos<span style="color: #666666">=2*</span>W)
+    d2 <span style="color: #666666">=</span> Dashpot(start<span style="color: #666666">=</span>(xpos,<span style="color: #666666">0</span>), total_length<span style="color: #666666">=1.2*</span>L, width<span style="color: #666666">=</span>W<span style="color: #666666">/2</span>,
+                 bar_length<span style="color: #666666">=</span>W, dashpot_length<span style="color: #666666">=</span>L<span style="color: #666666">/2</span>, piston_pos<span style="color: #666666">=2*</span>W)
     d2<span style="color: #666666">.</span>draw()
     d2<span style="color: #666666">.</span>draw()
     d2<span style="color: #666666">.</span>draw_dimensions()
     d2<span style="color: #666666">.</span>draw_dimensions()
 
 

+ 21 - 21
doc/pub/tutorial/html/_sources/main_sketcher.txt

@@ -9,7 +9,7 @@ Pysketcher: Create Principal Sketches of Physics Problems
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 
 :Authors: Hans Petter Langtangen
 :Authors: Hans Petter Langtangen
-:Date: Dec 22, 2015
+:Date: Dec 23, 2015
 
 
 
 
 .. The below box could be typeset as .. admonition: Attention
 .. The below box could be typeset as .. admonition: Attention
@@ -760,9 +760,9 @@ was produced by this code:
                 'a2': Distance_wText((0,2), (2, 0), t, fontsize),
                 'a2': Distance_wText((0,2), (2, 0), t, fontsize),
                 'a3': Distance_wText((2,4.5), (0, 5.5), t, fontsize),
                 'a3': Distance_wText((2,4.5), (0, 5.5), t, fontsize),
                 'a4': Distance_wText((8,4), (10, 3), t, fontsize,
                 'a4': Distance_wText((8,4), (10, 3), t, fontsize,
-                                     text_spacing=old_div(-1.,60)),
+                                     text_spacing=-1./60),
                 'a5': Distance_wText((8,2), (10, 1), t, fontsize,
                 'a5': Distance_wText((8,2), (10, 1), t, fontsize,
-                                     text_spacing=old_div(-1.,40), alignment='right'),
+                                     text_spacing=-1./40, alignment='right'),
                 'c1': Text_wArrow('text_spacing=-1./60',
                 'c1': Text_wArrow('text_spacing=-1./60',
                                   (4, 3.5), (9, 3.2),
                                   (4, 3.5), (9, 3.2),
                                   fontsize=10, alignment='left'),
                                   fontsize=10, alignment='left'),
@@ -796,12 +796,12 @@ The above figure can be produced by the following code.
             W = 4.0
             W = 4.0
         
         
             drawing_tool.set_coordinate_system(
             drawing_tool.set_coordinate_system(
-                xmin=0, xmax=2*W, ymin=old_div(-L,2), ymax=2*L,
+                xmin=0, xmax=2*W, ymin=-L/2, ymax=2*L,
                 axis=True, instruction_file='tmp_Rectangle.py')
                 axis=True, instruction_file='tmp_Rectangle.py')
             drawing_tool.set_linecolor('blue')
             drawing_tool.set_linecolor('blue')
             drawing_tool.set_grid(True)
             drawing_tool.set_grid(True)
         
         
-            xpos = old_div(W,2)
+            xpos = W/2
             r = Rectangle(lower_left_corner=(xpos,0), width=W, height=L)
             r = Rectangle(lower_left_corner=(xpos,0), width=W, height=L)
             r.draw()
             r.draw()
             r.draw_dimensions()
             r.draw_dimensions()
@@ -829,13 +829,13 @@ The code below produces the figure.
             W = 4.0
             W = 4.0
         
         
             drawing_tool.set_coordinate_system(
             drawing_tool.set_coordinate_system(
-                xmin=0, xmax=2*W, ymin=old_div(-L,2), ymax=1.2*L,
+                xmin=0, xmax=2*W, ymin=-L/2, ymax=1.2*L,
                 axis=True, instruction_file='tmp_Triangle.py')
                 axis=True, instruction_file='tmp_Triangle.py')
             drawing_tool.set_linecolor('blue')
             drawing_tool.set_linecolor('blue')
             drawing_tool.set_grid(True)
             drawing_tool.set_grid(True)
         
         
             xpos = 1
             xpos = 1
-            t = Triangle(p1=(old_div(W,2),0), p2=(3*W/2,old_div(W,2)), p3=(4*W/5.,L))
+            t = Triangle(p1=(W/2,0), p2=(3*W/2,W/2), p3=(4*W/5.,L))
             t.draw()
             t.draw()
             t.draw_dimensions()
             t.draw_dimensions()
             drawing_tool.display('Triangle')
             drawing_tool.display('Triangle')
@@ -863,13 +863,13 @@ An arc like the one above is produced by
             W = 4.0
             W = 4.0
         
         
             drawing_tool.set_coordinate_system(
             drawing_tool.set_coordinate_system(
-                xmin=old_div(-W,2), xmax=W, ymin=old_div(-L,2), ymax=1.5*L,
+                xmin=-W/2, xmax=W, ymin=-L/2, ymax=1.5*L,
                 axis=True, instruction_file='tmp_Arc.py')
                 axis=True, instruction_file='tmp_Arc.py')
             drawing_tool.set_linecolor('blue')
             drawing_tool.set_linecolor('blue')
             drawing_tool.set_grid(True)
             drawing_tool.set_grid(True)
         
         
             center = point(0,0)
             center = point(0,0)
-            radius = old_div(L,2)
+            radius = L/2
             start_angle = 60
             start_angle = 60
             arc_angle = 45
             arc_angle = 45
             a = Arc(center, radius, start_angle, arc_angle)
             a = Arc(center, radius, start_angle, arc_angle)
@@ -882,11 +882,11 @@ An arc like the one above is produced by
                 'start_angle':
                 'start_angle':
                 Arc_wText(
                 Arc_wText(
                     'start_angle', center, R1, start_angle=0,
                     'start_angle', center, R1, start_angle=0,
-                    arc_angle=start_angle, text_spacing=old_div(1,10.)),
+                    arc_angle=start_angle, text_spacing=1/10.),
                 'arc_angle':
                 'arc_angle':
                 Arc_wText(
                 Arc_wText(
                     'arc_angle', center, R2, start_angle=start_angle,
                     'arc_angle', center, R2, start_angle=start_angle,
-                    arc_angle=arc_angle, text_spacing=old_div(1,20.)),
+                    arc_angle=arc_angle, text_spacing=1/20.),
                 'r=0':
                 'r=0':
                 Line(center, center +
                 Line(center, center +
                      point(R*cos(radians(start_angle)),
                      point(R*cos(radians(start_angle)),
@@ -898,8 +898,8 @@ An arc like the one above is produced by
                 'r=start+arc_angle':
                 'r=start+arc_angle':
                 Line(center, center +
                 Line(center, center +
                      point(R, 0)).set_linestyle('dashed'),
                      point(R, 0)).set_linestyle('dashed'),
-                'radius': Distance_wText(center, a(0), 'radius', text_spacing=old_div(1,40.)),
-                'center': Text('center', center-point(old_div(radius,10.), old_div(radius,10.))),
+                'radius': Distance_wText(center, a(0), 'radius', text_spacing=1/40.),
+                'center': Text('center', center-point(radius/10., radius/10.)),
                 }
                 }
             for dimension in a.dimensions:
             for dimension in a.dimensions:
                 if dimension.startswith('r='):
                 if dimension.startswith('r='):
@@ -929,7 +929,7 @@ The code for making these two springs goes like this:
             W = 2.0
             W = 2.0
         
         
             drawing_tool.set_coordinate_system(
             drawing_tool.set_coordinate_system(
-                xmin=0, xmax=7*W, ymin=old_div(-L,2), ymax=1.5*L,
+                xmin=0, xmax=7*W, ymin=-L/2, ymax=1.5*L,
                 axis=True, instruction_file='tmp_Spring.py')
                 axis=True, instruction_file='tmp_Spring.py')
             drawing_tool.set_linecolor('blue')
             drawing_tool.set_linecolor('blue')
             drawing_tool.set_grid(True)
             drawing_tool.set_grid(True)
@@ -937,13 +937,13 @@ The code for making these two springs goes like this:
             xpos = W
             xpos = W
             s1 = Spring((W,0), L, teeth=True)
             s1 = Spring((W,0), L, teeth=True)
             s1_title = Text('Default Spring',
             s1_title = Text('Default Spring',
-                            s1.geometric_features()['end'] + point(0,old_div(L,10)))
+                            s1.geometric_features()['end'] + point(0,L/10))
             s1.draw()
             s1.draw()
             s1_title.draw()
             s1_title.draw()
             #s1.draw_dimensions()
             #s1.draw_dimensions()
             xpos += 3*W
             xpos += 3*W
-            s2 = Spring(start=(xpos,0), length=L, width=old_div(W,2.),
-                        bar_length=old_div(L,6.), teeth=False)
+            s2 = Spring(start=(xpos,0), length=L, width=W/2.,
+                        bar_length=L/6., teeth=False)
             s2.draw()
             s2.draw()
             s2.draw_dimensions()
             s2.draw_dimensions()
             drawing_tool.display('Spring')
             drawing_tool.display('Spring')
@@ -967,7 +967,7 @@ This dashpot is produced by
             xpos = 0
             xpos = 0
         
         
             drawing_tool.set_coordinate_system(
             drawing_tool.set_coordinate_system(
-                xmin=xpos, xmax=xpos+5.5*W, ymin=old_div(-L,2), ymax=1.5*L,
+                xmin=xpos, xmax=xpos+5.5*W, ymin=-L/2, ymax=1.5*L,
                 axis=True, instruction_file='tmp_Dashpot.py')
                 axis=True, instruction_file='tmp_Dashpot.py')
             drawing_tool.set_linecolor('blue')
             drawing_tool.set_linecolor('blue')
             drawing_tool.set_grid(True)
             drawing_tool.set_grid(True)
@@ -976,15 +976,15 @@ This dashpot is produced by
             xpos = 1.5
             xpos = 1.5
             d1 = Dashpot(start=(xpos,0), total_length=L)
             d1 = Dashpot(start=(xpos,0), total_length=L)
             d1_title = Text('Dashpot (default)',
             d1_title = Text('Dashpot (default)',
-                            d1.geometric_features()['end'] + point(0,old_div(L,10)))
+                            d1.geometric_features()['end'] + point(0,L/10))
             d1.draw()
             d1.draw()
             d1_title.draw()
             d1_title.draw()
         
         
             # Dashpot for animation with fixed bar_length, dashpot_length and
             # Dashpot for animation with fixed bar_length, dashpot_length and
             # prescribed piston_pos
             # prescribed piston_pos
             xpos += 2.5*W
             xpos += 2.5*W
-            d2 = Dashpot(start=(xpos,0), total_length=1.2*L, width=old_div(W,2),
-                         bar_length=W, dashpot_length=old_div(L,2), piston_pos=2*W)
+            d2 = Dashpot(start=(xpos,0), total_length=1.2*L, width=W/2,
+                         bar_length=W, dashpot_length=L/2, piston_pos=2*W)
             d2.draw()
             d2.draw()
             d2.draw_dimensions()
             d2.draw_dimensions()
         
         

File diff suppressed because it is too large
+ 21 - 21
doc/pub/tutorial/html/main_sketcher.html


File diff suppressed because it is too large
+ 1 - 1
doc/pub/tutorial/html/searchindex.js


+ 1 - 1
doc/pub/tutorial/pysketcher.html

@@ -175,7 +175,7 @@ MathJax.Hub.Config({
 <center>[2] <b>Department of Informatics, University of Oslo</b></center>
 <center>[2] <b>Department of Informatics, University of Oslo</b></center>
 <br>
 <br>
 <p>
 <p>
-<center><h4>Dec 22, 2015</h4></center> <!-- date -->
+<center><h4>Dec 23, 2015</h4></center> <!-- date -->
 <br>
 <br>
 <p>
 <p>
 
 

BIN
doc/pub/tutorial/pysketcher.pdf


+ 110 - 98
examples/beam2.py

@@ -1,101 +1,113 @@
 from pysketcher import *
 from pysketcher import *
 
 
-L = 8.0
-a = 3*L/4
-b = L - a
-H = 1.0
-xpos = 0.0
-ypos = 3.0
-
-drawing_tool.set_coordinate_system(xmin=-3, xmax=xpos+1.5*L,
-                                   ymin=0, ymax=ypos+5*H,
-                                   axis=False)
-drawing_tool.set_linecolor('blue')
-#drawing_tool.set_grid(True)
-drawing_tool.set_fontsize(16)
-
-A = point(xpos,ypos)
-
-beam = Rectangle(A, L, H)
-
-h = L/16  # size of support, clamped wall etc
-
-clamped = Rectangle(A - point(h,0) - point(0,2*h), h,
-                    6*h).set_filled_curves(pattern='/')
-
-load = ConstantBeamLoad(A + point(0,H), L, H)
-load.set_linewidth(1).set_linecolor('black')
-load_text = Text('$w$', load.geometric_features()['mid_top'] + point(0,h/2.))
-
-B = A + point(a, 0)
-C = B + point(b, 0)
-
-support = SimplySupportedBeam(B, h)  # pt B is simply supported
-
-
-R1 = Force(A-point(0,2*H), A, '$R_1$', text_spacing=1./20)
-R1.set_linewidth(3).set_linecolor('black')
-R2 = Force(B-point(0,2*H), support.geometric_features()['mid_support'],
-           '$R_2$', text_spacing=1./20)
-R2.set_linewidth(3).set_linecolor('black')
-M1 = Moment('$M_1$', center=A + point(-H, H/2), radius=H/2,
-            left=True, text_spacing=1/30.)
-M1.set_linecolor('black')
-
-ab_level = point(0, 3*h)
-a_dim = Distance_wText(A - ab_level, B - ab_level, '$a$')
-b_dim = Distance_wText(B - ab_level, C - ab_level, '$b$')
-dims = Composition({'a': a_dim, 'b': b_dim})
-symbols = Composition({'R1': R1, 'R2': R2, 'M1': M1,
-                       'w': load, 'w text': load_text,
-                       'A': Text('$A$', A+point(0.7*h,-0.9*h)),
-                       'B': Text('$B$', support.geometric_features()['mid_support']-point(h,0)),
-                       'C': Text('$C$', C+point(h/2,-h/2))})
-
-x_axis = Axis(A + point(L+h, H/2), 2*H, '$x$',).set_linecolor('black')
-y_axis = Axis(A + point(0,H/2), 3.5*H, '$y$',
-              label_alignment='left',
-              rotation_angle=90).set_linecolor('black')
-axes = Composition({'x axis': x_axis, 'y axis': y_axis})
-
-annotations = Composition({'dims': dims, 'symbols': symbols,
-                           'axes': axes})
-fig = Composition({'beam': beam, 'support': support,
-                   'clamped end': clamped, 'load': load})
-
-def deflection(x, a, b, w):
-    import numpy as np
-    R1 = 5./8*w*a - 3*w*b**2/(4*a)
-    R2 = 3./8*w*a + w*b + 3*w*b**2/(4*a)
-    M1 = R1*a/3 - w*a**2/12
-    y = -(M1/2.)*x**2 + 1./6*R1*x**3 - w/24.*x**4 + \
-        1./6*R2*np.where(x > a, 1, 0)*(x-a)**3
-    return y
-
-x = linspace(0, L, 101)
-y = deflection(x, a, b, w=1.0)
-y /= abs(y.max() - y.min())
-y += ypos + H/2
-
-elastic_line = Curve(x, y).set_linecolor('red').set_linestyle('dashed').set_linewidth(3)
-
-fig.draw()
-drawing_tool.display()
-drawing_tool.savefig('tmp_beam2_1.png')
-
-import time
-time.sleep(1.5)
-
-annotations.draw()
-drawing_tool.display()
-drawing_tool.savefig('tmp_beam2_2.png')
-time.sleep(1.5)
-
-elastic_line.draw()
-drawing_tool.display()
-drawing_tool.savefig('tmp_beam2_3.png')
-#beam.draw_dimensions()
-
-#test_Dashpot(xpos+2*W)
-
+def beam():
+    L = 8.0
+    a = 3*L/4
+    b = L - a
+    H = 1.0
+    xpos = 0.0
+    ypos = 3.0
+
+    drawing_tool.set_coordinate_system(
+        xmin=-3, xmax=xpos+1.5*L,
+        ymin=0, ymax=ypos+5*H,
+        axis=False)
+    drawing_tool.set_linecolor('blue')
+    #drawing_tool.set_grid(True)
+    drawing_tool.set_fontsize(16)
+
+    A = point(xpos,ypos)
+
+    beam = Rectangle(A, L, H)
+
+    h = L/16  # size of support, clamped wall etc
+
+    clamped = Rectangle(A - point(h,0) - point(0,2*h), h,
+                        6*h).set_filled_curves(pattern='/')
+
+    load = ConstantBeamLoad(A + point(0,H), L, H)
+    load.set_linewidth(1).set_linecolor('black')
+    load_text = Text('$w$',
+                     load.geometric_features()['mid_top'] +
+                     point(0,h/2.))
+
+    B = A + point(a, 0)
+    C = B + point(b, 0)
+
+    support = SimplySupportedBeam(B, h)  # pt B is simply supported
+
+
+    R1 = Force(A-point(0,2*H), A, '$R_1$', text_spacing=1./50)
+    R1.set_linewidth(3).set_linecolor('black')
+    R2 = Force(B-point(0,2*H),
+               support.geometric_features()['mid_support'],
+               '$R_2$', text_spacing=1./50)
+    R2.set_linewidth(3).set_linecolor('black')
+    M1 = Moment('$M_1$', center=A + point(-H, H/2), radius=H/2,
+                left=True, text_spacing=1/30.)
+    M1.set_linecolor('black')
+
+    ab_level = point(0, 3*h)
+    a_dim = Distance_wText(A - ab_level, B - ab_level, '$a$')
+    b_dim = Distance_wText(B - ab_level, C - ab_level, '$b$')
+    dims = Composition({'a': a_dim, 'b': b_dim})
+    symbols = Composition(
+        {'R1': R1, 'R2': R2, 'M1': M1,
+         'w': load, 'w text': load_text,
+         'A': Text('$A$', A+point(0.7*h,-0.9*h)),
+         'B': Text('$B$',
+                   support.geometric_features()['mid_support']-
+                   point(1.25*h,0)),
+         'C': Text('$C$', C+point(h/2,-h/2))})
+
+    x_axis = Axis(A + point(L+h, H/2), 2*H, '$x$',).\
+             set_linecolor('black')
+    y_axis = Axis(A + point(0,H/2), 3.5*H, '$y$',
+                  label_alignment='left',
+                  rotation_angle=90).set_linecolor('black')
+    axes = Composition({'x axis': x_axis, 'y axis': y_axis})
+
+    annotations = Composition({'dims': dims, 'symbols': symbols,
+                               'axes': axes})
+    beam = Composition({'beam': beam, 'support': support,
+                        'clamped end': clamped, 'load': load})
+
+    def deflection(x, a, b, w):
+        import numpy as np
+        R1 = 5./8*w*a - 3*w*b**2/(4*a)
+        R2 = 3./8*w*a + w*b + 3*w*b**2/(4*a)
+        M1 = R1*a/3 - w*a**2/12
+        y = -(M1/2.)*x**2 + 1./6*R1*x**3 - w/24.*x**4 + \
+            1./6*R2*np.where(x > a, 1, 0)*(x-a)**3
+        return y
+
+    x = linspace(0, L, 101)
+    y = deflection(x, a, b, w=1.0)
+    y /= abs(y.max() - y.min())
+    y += ypos + H/2
+
+    elastic_line = Curve(x, y).\
+                   set_linecolor('red').\
+                   set_linestyle('dashed').\
+                   set_linewidth(3)
+
+    beam.draw()
+    drawing_tool.display()
+    drawing_tool.savefig('tmp_beam2_1.png')
+
+    import time
+    time.sleep(1.5)
+
+    annotations.draw()
+    drawing_tool.display()
+    drawing_tool.savefig('tmp_beam2_2.png')
+    time.sleep(1.5)
+
+    elastic_line.draw()
+    drawing_tool.display()
+    drawing_tool.savefig('tmp_beam2_3.png')
+    #beam.draw_dimensions()
+    #test_Dashpot(xpos+2*W)
+
+beam()
 input()
 input()

+ 15 - 15
pysketcher/MatplotlibDraw.py

@@ -8,7 +8,7 @@ from builtins import input
 from builtins import str
 from builtins import str
 from builtins import *
 from builtins import *
 from builtins import object
 from builtins import object
-from past.utils import old_div
+
 import os
 import os
 import matplotlib
 import matplotlib
 matplotlib.use('TkAgg')
 matplotlib.use('TkAgg')
@@ -64,8 +64,8 @@ class MatplotlibDraw(object):
         x_space = new_x_range - x_range
         x_space = new_x_range - x_range
         new_y_range = y_range*100./occupation_percent
         new_y_range = y_range*100./occupation_percent
         y_space = new_y_range - y_range
         y_space = new_y_range - y_range
-        self.ax.set_xlim(minmax['xmin']-old_div(x_space,2.), minmax['xmax']+old_div(x_space,2.))
-        self.ax.set_ylim(minmax['ymin']-old_div(y_space,2.), minmax['ymax']+old_div(y_space,2.))
+        self.ax.set_xlim(minmax['xmin']-x_space/2., minmax['xmax']+x_space/2.)
+        self.ax.set_ylim(minmax['ymin']-y_space/2., minmax['ymax']+y_space/2.)
 
 
     def set_coordinate_system(self, xmin, xmax, ymin, ymax, axis=False,
     def set_coordinate_system(self, xmin, xmax, ymin, ymax, axis=False,
                               instruction_file=None, new_figure=True,
                               instruction_file=None, new_figure=True,
@@ -99,7 +99,7 @@ class MatplotlibDraw(object):
 
 
         # Compute the right X11 geometry on the screen based on the
         # Compute the right X11 geometry on the screen based on the
         # x-y ratio of axis ranges
         # x-y ratio of axis ranges
-        ratio = old_div((self.ymax-self.ymin),(self.xmax-self.xmin))
+        ratio = (self.ymax-self.ymin)/(self.xmax-self.xmin)
         self.xsize = 800  # pixel size
         self.xsize = 800  # pixel size
         self.ysize = self.xsize*ratio
         self.ysize = self.xsize*ratio
         geometry = '%dx%d' % (self.xsize, self.ysize)
         geometry = '%dx%d' % (self.xsize, self.ysize)
@@ -283,9 +283,15 @@ ax.set_aspect('equal')
             if self.instruction_file:
             if self.instruction_file:
                 self.instruction_file.write("[line] = ax.fill(x, y, '%s', edgecolor='%s', linewidth=%d, hatch='%s')\n" % (fillcolor, linecolor, linewidth, fillpattern))
                 self.instruction_file.write("[line] = ax.fill(x, y, '%s', edgecolor='%s', linewidth=%d, hatch='%s')\n" % (fillcolor, linecolor, linewidth, fillpattern))
 
 
-        elif arrow:
+        else:
+            # Plain line
+            [line] = self.ax.plot(x, y, linecolor, linewidth=linewidth,
+                                  linestyle=linestyle)
+            if self.instruction_file:
+                self.instruction_file.write("[line] = ax.plot(x, y, '%s', linewidth=%d, linestyle='%s')\n" % (linecolor, linewidth, linestyle))
+
+        if arrow:
             # Note that a Matplotlib arrow is a line with the arrow tip
             # Note that a Matplotlib arrow is a line with the arrow tip
-            # (do not draw the line in addition)
             if not arrow in ('->', '<-', '<->'):
             if not arrow in ('->', '<-', '<->'):
                 raise ValueError("arrow argument must be '->', '<-', or '<->', not %s" % repr(arrow))
                 raise ValueError("arrow argument must be '->', '<-', or '<->', not %s" % repr(arrow))
 
 
@@ -302,17 +308,10 @@ ax.set_aspect('equal')
                 dx_e, dy_e = x[-1]-x[-2], y[-1]-y[-2]
                 dx_e, dy_e = x[-1]-x[-2], y[-1]-y[-2]
                 self._plot_arrow(x_e, y_e, dx_e, dy_e, '->',
                 self._plot_arrow(x_e, y_e, dx_e, dy_e, '->',
                                  linestyle, linewidth, linecolor)
                                  linestyle, linewidth, linecolor)
-        else:
-            # Plain line
-            [line] = self.ax.plot(x, y, linecolor, linewidth=linewidth,
-                                  linestyle=linestyle)
-            if self.instruction_file:
-                self.instruction_file.write("[line] = ax.plot(x, y, '%s', linewidth=%d, linestyle='%s')\n" % (linecolor, linewidth, linestyle))
-
         if shadow:
         if shadow:
             # http://matplotlib.sourceforge.net/users/transforms_tutorial.html#using-offset-transforms-to-create-a-shadow-effect
             # http://matplotlib.sourceforge.net/users/transforms_tutorial.html#using-offset-transforms-to-create-a-shadow-effect
             # shift the object over 2 points, and down 2 points
             # shift the object over 2 points, and down 2 points
-            dx, dy = old_div(shadow,72.), old_div(-shadow,72.)
+            dx, dy = shadow/72., -shadow/72.
             offset = transforms.ScaledTranslation(
             offset = transforms.ScaledTranslation(
                 dx, dy, self.fig.dpi_scale_trans)
                 dx, dy, self.fig.dpi_scale_trans)
             shadow_transform = self.ax.transData + offset
             shadow_transform = self.ax.transData + offset
@@ -446,7 +445,8 @@ ax.annotate('%s', xy=%s, xycoords='data',
                             linewidth=2,
                             linewidth=2,
                             shrinkA=5,
                             shrinkA=5,
                             shrinkB=5))
                             shrinkB=5))
-""" % (text, pt, position, alignment, fontsize))
+""" % (text, pt.tolist() if isinstance(pt, np.ndarray) else pt,
+       position, alignment, fontsize))
 
 
 # Drawing annotations with arrows:
 # Drawing annotations with arrows:
 #http://matplotlib.sourceforge.net/users/annotations_intro.html
 #http://matplotlib.sourceforge.net/users/annotations_intro.html

+ 48 - 50
pysketcher/shapes.py

@@ -10,7 +10,6 @@ from builtins import str
 from builtins import range
 from builtins import range
 from builtins import *
 from builtins import *
 from builtins import object
 from builtins import object
-from past.utils import old_div
 from numpy import linspace, sin, cos, pi, array, asarray, ndarray, sqrt, abs
 from numpy import linspace, sin, cos, pi, array, asarray, ndarray, sqrt, abs
 import pprint, copy, glob, os
 import pprint, copy, glob, os
 from math import radians
 from math import radians
@@ -48,7 +47,7 @@ def unit_vec(x, y=None):
     if isinstance(x, (float,int)) and isinstance(y, (float,int)):
     if isinstance(x, (float,int)) and isinstance(y, (float,int)):
         x = point(x, y)
         x = point(x, y)
     elif isinstance(x, (list,tuple,ndarray)) and y is None:
     elif isinstance(x, (list,tuple,ndarray)) and y is None:
-        return old_div(arr2D(x),sqrt(x[0]**2 + x[1]**2))
+        return arr2D(x)/sqrt(x[0]**2 + x[1]**2)
     else:
     else:
         raise TypeError('x=%s is %s, must be float or ndarray 2D point' %
         raise TypeError('x=%s is %s, must be float or ndarray 2D point' %
                         (x, type(x)))
                         (x, type(x)))
@@ -233,7 +232,7 @@ class Shape(object):
                 shape_name = shape
                 shape_name = shape
                 shape = self.shapes[shape]
                 shape = self.shapes[shape]
             else:
             else:
-                shape_name = k  # use index as name if list
+                shape_name = k  # use index as name if list (not dict)
 
 
             if not isinstance(shape, Shape):
             if not isinstance(shape, Shape):
                 if isinstance(shape, dict):
                 if isinstance(shape, dict):
@@ -833,14 +832,14 @@ class Rectangle(Shape):
 
 
         # Dimensions
         # Dimensions
         dims = {
         dims = {
-            'width': Distance_wText(p + point(0, old_div(-height,5.)),
-                                    p + point(width, old_div(-height,5.)),
+            'width': Distance_wText(p + point(0, -height/5.),
+                                    p + point(width, -height/5.),
                                     'width'),
                                     'width'),
-            'height': Distance_wText(p + point(width + old_div(width,5.), 0),
-                                     p + point(width + old_div(width,5.), height),
+            'height': Distance_wText(p + point(width + width/5., 0),
+                                     p + point(width + width/5., height),
                                    'height'),
                                    'height'),
             'lower_left_corner': Text_wArrow('lower_left_corner',
             'lower_left_corner': Text_wArrow('lower_left_corner',
-                                             p - point(old_div(width,5.), old_div(height,5.)), p)
+                                             p - point(width/5., height/5.), p)
             }
             }
         self.dimensions = dims
         self.dimensions = dims
 
 
@@ -920,7 +919,7 @@ class Line(Shape):
         # Define equations for line:
         # Define equations for line:
         # y = a*x + b,  x = c*y + d
         # y = a*x + b,  x = c*y + d
         try:
         try:
-            self.a = old_div((y[1] - y[0]),(x[1] - x[0]))
+            self.a = (y[1] - y[0])/(x[1] - x[0])
             self.b = y[0] - self.a*x[0]
             self.b = y[0] - self.a*x[0]
         except ZeroDivisionError:
         except ZeroDivisionError:
             # Vertical line, y is not a function of x
             # Vertical line, y is not a function of x
@@ -930,7 +929,7 @@ class Line(Shape):
             if self.a is None:
             if self.a is None:
                 self.c = 0
                 self.c = 0
             else:
             else:
-                self.c = old_div(1,float(self.a))
+                self.c = 1/float(self.a)
             if self.b is None:
             if self.b is None:
                 self.d = x[1]
                 self.d = x[1]
         except ZeroDivisionError:
         except ZeroDivisionError:
@@ -945,7 +944,7 @@ class Line(Shape):
         # Define equations for line:
         # Define equations for line:
         # y = a*x + b,  x = c*y + d
         # y = a*x + b,  x = c*y + d
         if abs(x[1] - x[0]) > tol:
         if abs(x[1] - x[0]) > tol:
-            self.a = old_div((y[1] - y[0]),(x[1] - x[0]))
+            self.a = (y[1] - y[0])/(x[1] - x[0])
             self.b = y[0] - self.a*x[0]
             self.b = y[0] - self.a*x[0]
         else:
         else:
             # Vertical line, y is not a function of x
             # Vertical line, y is not a function of x
@@ -954,7 +953,7 @@ class Line(Shape):
         if self.a is None:
         if self.a is None:
             self.c = 0
             self.c = 0
         elif abs(self.a) > tol:
         elif abs(self.a) > tol:
-            self.c = old_div(1,float(self.a))
+            self.c = 1/float(self.a)
             self.d = x[1]
             self.d = x[1]
         else:  # self.a is 0
         else:  # self.a is 0
             # Horizontal line, x is not a function of y
             # Horizontal line, x is not a function of y
@@ -1033,10 +1032,9 @@ class Arc(Shape):
         # Cannot set dimensions (Arc_wText recurses into this
         # Cannot set dimensions (Arc_wText recurses into this
         # constructor forever). Set in test_Arc instead.
         # constructor forever). Set in test_Arc instead.
 
 
-        # Stored geometric features
     def geometric_features(self):
     def geometric_features(self):
         a = self.shapes['arc']
         a = self.shapes['arc']
-        m = old_div(len(a.x),2)  # mid point in array
+        m = len(a.x)//2  # mid point in array
         d = {'start': point(a.x[0], a.y[0]),
         d = {'start': point(a.x[0], a.y[0]),
              'end': point(a.x[-1], a.y[-1]),
              'end': point(a.x[-1], a.y[-1]),
              'mid': point(a.x[m], a.y[m])}
              'mid': point(a.x[m], a.y[m])}
@@ -1220,7 +1218,7 @@ class VelocityProfile(Shape):
         shapes['start line'] = Line(start, (start[0], start[1]+height))
         shapes['start line'] = Line(start, (start[0], start[1]+height))
 
 
         # Draw velocity arrows
         # Draw velocity arrows
-        dy = old_div(float(height),(num_arrows-1))
+        dy = float(height)/(num_arrows-1)
         x = start[0]
         x = start[0]
         y = start[1]
         y = start[1]
         r = profile(y)  # Test on return type
         r = profile(y)  # Test on return type
@@ -1240,7 +1238,7 @@ class VelocityProfile(Shape):
         xs = []
         xs = []
         ys = []
         ys = []
         n = 100
         n = 100
-        dy = old_div(float(height),n)
+        dy = float(height)/n
         for i in range(n+2):
         for i in range(n+2):
             y = start[1] + i*dy
             y = start[1] + i*dy
             vx, vy = profile(y)
             vx, vy = profile(y)
@@ -1276,7 +1274,7 @@ class Arrow3(Shape):
         top = (self.bottom[0], self.bottom[1] + self.length)
         top = (self.bottom[0], self.bottom[1] + self.length)
         main = Line(self.bottom, top)
         main = Line(self.bottom, top)
         #head_length = self.length/8.0
         #head_length = self.length/8.0
-        head_length = old_div(drawing_tool.xrange,50.)
+        head_length = drawing_tool.xrange/50.
         head_degrees = radians(30)
         head_degrees = radians(30)
         head_left_pt = (top[0] - head_length*sin(head_degrees),
         head_left_pt = (top[0] - head_length*sin(head_degrees),
                         top[1] - head_length*cos(head_degrees))
                         top[1] - head_length*cos(head_degrees))
@@ -1354,7 +1352,7 @@ class Text_wArrow(Text):
 class Axis(Shape):
 class Axis(Shape):
     def __init__(self, start, length, label,
     def __init__(self, start, length, label,
                  rotation_angle=0, fontsize=0,
                  rotation_angle=0, fontsize=0,
-                 label_spacing=old_div(1.,45), label_alignment='left'):
+                 label_spacing=1./45, label_alignment='left'):
         """
         """
         Draw axis from start with `length` to the right
         Draw axis from start with `length` to the right
         (x axis). Place label at the end of the arrow tip.
         (x axis). Place label at the end of the arrow tip.
@@ -1400,7 +1398,7 @@ class Force(Arrow1):
     a distance `text_spacing` times the width of the total plotting
     a distance `text_spacing` times the width of the total plotting
     area away from the specified point.
     area away from the specified point.
     """
     """
-    def __init__(self, start, end, text, text_spacing=old_div(1.,60),
+    def __init__(self, start, end, text, text_spacing=1./60,
                  fontsize=0, text_pos='start', text_alignment='center'):
                  fontsize=0, text_pos='start', text_alignment='center'):
         Arrow1.__init__(self, start, end, style='->')
         Arrow1.__init__(self, start, end, style='->')
         if isinstance(text_spacing, (tuple,list)):
         if isinstance(text_spacing, (tuple,list)):
@@ -1447,7 +1445,7 @@ class Force(Arrow1):
 class Axis2(Force):
 class Axis2(Force):
     def __init__(self, start, length, label,
     def __init__(self, start, length, label,
                  rotation_angle=0, fontsize=0,
                  rotation_angle=0, fontsize=0,
-                 label_spacing=old_div(1.,45), label_alignment='left'):
+                 label_spacing=1./45, label_alignment='left'):
         direction = point(cos(radians(rotation_angle)),
         direction = point(cos(radians(rotation_angle)),
                           sin(radians(rotation_angle)))
                           sin(radians(rotation_angle)))
         Force.__init__(start=start, end=length*direction, text=label,
         Force.__init__(start=start, end=length*direction, text=label,
@@ -1464,7 +1462,7 @@ class Gravity(Axis):
     """Downward-pointing gravity arrow with the symbol g."""
     """Downward-pointing gravity arrow with the symbol g."""
     def __init__(self, start, length, fontsize=0):
     def __init__(self, start, length, fontsize=0):
         Axis.__init__(self, start, length, '$g$', below=False,
         Axis.__init__(self, start, length, '$g$', below=False,
-                      rotation_angle=-90, label_spacing=old_div(1.,30),
+                      rotation_angle=-90, label_spacing=1./30,
                       fontsize=fontsize)
                       fontsize=fontsize)
         self.shapes['arrow'].set_linecolor('black')
         self.shapes['arrow'].set_linecolor('black')
 
 
@@ -1473,7 +1471,7 @@ class Gravity(Force):
     """Downward-pointing gravity arrow with the symbol g."""
     """Downward-pointing gravity arrow with the symbol g."""
     def __init__(self, start, length, text='$g$', fontsize=0):
     def __init__(self, start, length, text='$g$', fontsize=0):
         Force.__init__(self, start, (start[0], start[1]-length),
         Force.__init__(self, start, (start[0], start[1]-length),
-                       text, text_spacing=old_div(1.,60),
+                       text, text_spacing=1./60,
                        fontsize=0, text_pos='end')
                        fontsize=0, text_pos='end')
         self.shapes['arrow'].set_linecolor('black')
         self.shapes['arrow'].set_linecolor('black')
 
 
@@ -1488,7 +1486,7 @@ class Distance_wText(Shape):
     horizontal-like arrows, the text is placed the same distance
     horizontal-like arrows, the text is placed the same distance
     above, but aligned 'center' by default (when `alignment` is None).
     above, but aligned 'center' by default (when `alignment` is None).
     """
     """
-    def __init__(self, start, end, text, fontsize=0, text_spacing=old_div(1,60.),
+    def __init__(self, start, end, text, fontsize=0, text_spacing=1/60.,
                  alignment=None, text_pos='mid'):
                  alignment=None, text_pos='mid'):
         start = arr2D(start)
         start = arr2D(start)
         end   = arr2D(end)
         end   = arr2D(end)
@@ -1535,10 +1533,10 @@ class Distance_wText(Shape):
 class Arc_wText(Shape):
 class Arc_wText(Shape):
     def __init__(self, text, center, radius,
     def __init__(self, text, center, radius,
                  start_angle, arc_angle, fontsize=0,
                  start_angle, arc_angle, fontsize=0,
-                 resolution=180, text_spacing=old_div(1,60.)):
+                 resolution=180, text_spacing=1/60.):
         arc = Arc(center, radius, start_angle, arc_angle,
         arc = Arc(center, radius, start_angle, arc_angle,
                   resolution)
                   resolution)
-        mid = arr2D(arc(old_div(arc_angle,2.)))
+        mid = arr2D(arc(arc_angle/2.))
         normal = unit_vec(mid - arr2D(center))
         normal = unit_vec(mid - arr2D(center))
         text_pos = mid + normal*drawing_tool.xrange*text_spacing
         text_pos = mid + normal*drawing_tool.xrange*text_spacing
         self.shapes = {'arc': arc,
         self.shapes = {'arc': arc,
@@ -1568,11 +1566,11 @@ class Composition(Shape):
 class SimplySupportedBeam(Shape):
 class SimplySupportedBeam(Shape):
     def __init__(self, pos, size):
     def __init__(self, pos, size):
         pos = arr2D(pos)
         pos = arr2D(pos)
-        P0 = (pos[0] - old_div(size,2.), pos[1]-size)
-        P1 = (pos[0] + old_div(size,2.), pos[1]-size)
+        P0 = (pos[0] - size/2., pos[1]-size)
+        P1 = (pos[0] + size/2., pos[1]-size)
         triangle = Triangle(P0, P1, pos)
         triangle = Triangle(P0, P1, pos)
-        gap = old_div(size,5.)
-        h = old_div(size,4.)  # height of rectangle
+        gap = size/5.
+        h = size/4.  # height of rectangle
         P2 = (P0[0], P0[1]-gap-h)
         P2 = (P0[0], P0[1]-gap-h)
         rectangle = Rectangle(P2, size, h).set_filled_curves(pattern='/')
         rectangle = Rectangle(P2, size, h).set_filled_curves(pattern='/')
         self.shapes = {'triangle': triangle, 'rectangle': rectangle}
         self.shapes = {'triangle': triangle, 'rectangle': rectangle}
@@ -1607,7 +1605,7 @@ class ConstantBeamLoad(Shape):
     def __init__(self, lower_left_corner, width, height, num_arrows=10):
     def __init__(self, lower_left_corner, width, height, num_arrows=10):
         box = Rectangle(lower_left_corner, width, height)
         box = Rectangle(lower_left_corner, width, height)
         self.shapes = {'box': box}
         self.shapes = {'box': box}
-        dx = old_div(float(width),(num_arrows-1))
+        dx = float(width)/(num_arrows-1)
         y_top = lower_left_corner[1] + height
         y_top = lower_left_corner[1] + height
         y_tip = lower_left_corner[1]
         y_tip = lower_left_corner[1]
         for i in range(num_arrows):
         for i in range(num_arrows):
@@ -1621,7 +1619,7 @@ class ConstantBeamLoad(Shape):
 class Moment(Arc_wText):
 class Moment(Arc_wText):
     def __init__(self, text, center, radius,
     def __init__(self, text, center, radius,
                  left=True, counter_clockwise=True,
                  left=True, counter_clockwise=True,
-                 fontsize=0, text_spacing=old_div(1,60.)):
+                 fontsize=0, text_spacing=1/60.):
         style = '->' if counter_clockwise else '<-'
         style = '->' if counter_clockwise else '<-'
         start_angle = 90 if left else -90
         start_angle = 90 if left else -90
         Arc_wText.__init__(self, text, center, radius,
         Arc_wText.__init__(self, text, center, radius,
@@ -1629,13 +1627,13 @@ class Moment(Arc_wText):
                            arc_angle=180, fontsize=fontsize,
                            arc_angle=180, fontsize=fontsize,
                            text_spacing=text_spacing,
                            text_spacing=text_spacing,
                            resolution=180)
                            resolution=180)
-        self.shapes['arc'].set_arrow(style)
+        self.shapes['arc']['arc'].set_arrow(style)  # Curve object
 
 
 
 
 class Wheel(Shape):
 class Wheel(Shape):
     def __init__(self, center, radius, inner_radius=None, nlines=10):
     def __init__(self, center, radius, inner_radius=None, nlines=10):
         if inner_radius is None:
         if inner_radius is None:
-            inner_radius = old_div(radius,5.0)
+            inner_radius = radius/5.0
 
 
         outer = Circle(center, radius)
         outer = Circle(center, radius)
         inner = Circle(center, inner_radius)
         inner = Circle(center, inner_radius)
@@ -1666,7 +1664,7 @@ class SineWave(Shape):
         self.amplitude = amplitude
         self.amplitude = amplitude
         self.mean_level = mean_level
         self.mean_level = mean_level
 
 
-        npoints = old_div((self.xstop - self.xstart),(old_div(self.wavelength,61.0)))
+        npoints = (self.xstop - self.xstart)/(self.wavelength/61.0)
         x = linspace(self.xstart, self.xstop, npoints)
         x = linspace(self.xstart, self.xstop, npoints)
         k = 2*pi/self.wavelength # frequency
         k = 2*pi/self.wavelength # frequency
         y = self.mean_level + self.amplitude*sin(k*x)
         y = self.mean_level + self.amplitude*sin(k*x)
@@ -1687,7 +1685,7 @@ class Spring(Shape):
     (these parameters can later be extracted as attributes, see table
     (these parameters can later be extracted as attributes, see table
     below).
     below).
     """
     """
-    spring_fraction = old_div(1.,2)  # fraction of total length occupied by spring
+    spring_fraction = 1./2  # fraction of total length occupied by spring
 
 
     def __init__(self, start, length, width=None, bar_length=None,
     def __init__(self, start, length, width=None, bar_length=None,
                  num_windings=11, teeth=False):
                  num_windings=11, teeth=False):
@@ -1700,9 +1698,9 @@ class Spring(Shape):
             n = n+1
             n = n+1
         L = length
         L = length
         if width is None:
         if width is None:
-            w = old_div(L,10.)
+            w = L/10.
         else:
         else:
-            w = old_div(width,2.0)
+            w = width/2.0
         s = bar_length
         s = bar_length
 
 
         # [0, x, L-x, L], f = (L-2*x)/L
         # [0, x, L-x, L], f = (L-2*x)/L
@@ -1733,7 +1731,7 @@ class Spring(Shape):
 
 
         shapes['bar1'] = Line(B, P0)
         shapes['bar1'] = Line(B, P0)
         spring_length = L - 2*s
         spring_length = L - 2*s
-        t = old_div(spring_length,n)  # height increment per winding
+        t = spring_length/n  # height increment per winding
         if teeth:
         if teeth:
             resolution = 4
             resolution = 4
         else:
         else:
@@ -1753,7 +1751,7 @@ class Spring(Shape):
                                 'length')
                                 'length')
         num_windings = Text_wArrow('num_windings',
         num_windings = Text_wArrow('num_windings',
                                    (B[0]+2*w,P2[1]+w),
                                    (B[0]+2*w,P2[1]+w),
-                                   (B[0]+1.2*w, B[1]+old_div(L,2.)))
+                                   (B[0]+1.2*w, B[1]+L/2.))
         blength1 = Distance_wText((B[0]-2*w, B[1]), (B[0]-2*w, P0[1]),
         blength1 = Distance_wText((B[0]-2*w, B[1]), (B[0]-2*w, P0[1]),
                                        'bar_length',
                                        'bar_length',
                                        text_pos=(P0[0]-7*w, P0[1]+w))
                                        text_pos=(P0[0]-7*w, P0[1]+w))
@@ -1802,18 +1800,18 @@ class Dashpot(Shape):
     ``geometric_features``.
     ``geometric_features``.
 
 
     """
     """
-    dashpot_fraction = old_div(1.,2)            # fraction of total_length
-    piston_gap_fraction = old_div(1.,6)         # fraction of width
-    piston_thickness_fraction = old_div(1.,8)   # fraction of dashplot_length
+    dashpot_fraction = 1./2            # fraction of total_length
+    piston_gap_fraction = 1./6         # fraction of width
+    piston_thickness_fraction = 1./8   # fraction of dashplot_length
 
 
     def __init__(self, start, total_length, bar_length=None,
     def __init__(self, start, total_length, bar_length=None,
                  width=None, dashpot_length=None, piston_pos=None):
                  width=None, dashpot_length=None, piston_pos=None):
         B = start
         B = start
         L = total_length
         L = total_length
         if width is None:
         if width is None:
-            w = old_div(L,10.)    # total width 1/5 of length
+            w = L/10.    # total width 1/5 of length
         else:
         else:
-            w = old_div(width,2.0)
+            w = width/2.0
         s = bar_length
         s = bar_length
 
 
         # [0, x, L-x, L], f = (L-2*x)/L
         # [0, x, L-x, L], f = (L-2*x)/L
@@ -1837,7 +1835,7 @@ class Dashpot(Shape):
             dashpot_length = f*L
             dashpot_length = f*L
         else:
         else:
             if s is None:
             if s is None:
-                f = old_div(1.,2)  # the bar lengths are taken as f*dashpot_length
+                f = 1./2  # the bar lengths are taken as f*dashpot_length
                 s = f*dashpot_length # default
                 s = f*dashpot_length # default
             P1 = (B[0], B[1]+s+dashpot_length)
             P1 = (B[0], B[1]+s+dashpot_length)
         P0 = (B[0], B[1]+s)
         P0 = (B[0], B[1]+s)
@@ -1950,7 +1948,7 @@ class Wavy(Shape):
 
 
         A_0 = amplitude_of_perturbations
         A_0 = amplitude_of_perturbations
         A_p = 0.3*A_0
         A_p = 0.3*A_0
-        A_k = old_div(k_0,2)
+        A_k = k_0/2
 
 
         x = linspace(xmin, xmax, 2001)
         x = linspace(xmin, xmax, 2001)
 
 
@@ -2583,8 +2581,8 @@ def _test5():
     c = 6.  # center point of box
     c = 6.  # center point of box
     w = 2.  # size of box
     w = 2.  # size of box
     L = 3
     L = 3
-    r1 = Rectangle((c-old_div(w,2), c-old_div(w,2)), w, w)
-    l1 = Line((c,c-old_div(w,2)), (c,c-old_div(w,2)-L))
+    r1 = Rectangle((c-w/2, c-w/2), w, w)
+    l1 = Line((c,c-w/2), (c,c-w/2-L))
     linecolor('blue')
     linecolor('blue')
     filled_curves(True)
     filled_curves(True)
     r1.draw()
     r1.draw()
@@ -2604,9 +2602,9 @@ def rolling_wheel(total_rotation_angle):
     angle = 2.0
     angle = 2.0
     pngfiles = []
     pngfiles = []
     w1 = Wheel(center=center, radius=radius, inner_radius=0.5, nlines=7)
     w1 = Wheel(center=center, radius=radius, inner_radius=0.5, nlines=7)
-    for i in range(int(old_div(total_rotation_angle,angle))):
+    for i in range(int(total_rotation_angle/angle)):
         w1.draw()
         w1.draw()
-        print('XXXX BIG PROBLEM WITH ANIMATE!!!')
+        print('BIG PROBLEM WITH ANIMATE!!!')
         display()
         display()
 
 
 
 

+ 216 - 21
pysketcher/tests/test_pysketcher.py

@@ -6,7 +6,6 @@ from future import standard_library
 standard_library.install_aliases()
 standard_library.install_aliases()
 from builtins import zip
 from builtins import zip
 from builtins import *
 from builtins import *
-from past.utils import old_div
 from pysketcher import *
 from pysketcher import *
 
 
 def equal_dict(d1, d2):
 def equal_dict(d1, d2):
@@ -88,9 +87,9 @@ def test_Distance_wText():
         'a2': Distance_wText((0,2), (2, 0), t, fontsize),
         'a2': Distance_wText((0,2), (2, 0), t, fontsize),
         'a3': Distance_wText((2,4.5), (0, 5.5), t, fontsize),
         'a3': Distance_wText((2,4.5), (0, 5.5), t, fontsize),
         'a4': Distance_wText((8,4), (10, 3), t, fontsize,
         'a4': Distance_wText((8,4), (10, 3), t, fontsize,
-                             text_spacing=old_div(-1.,60)),
+                             text_spacing=-1./60),
         'a5': Distance_wText((8,2), (10, 1), t, fontsize,
         'a5': Distance_wText((8,2), (10, 1), t, fontsize,
-                             text_spacing=old_div(-1.,40), alignment='right'),
+                             text_spacing=-1./40, alignment='right'),
         'c1': Text_wArrow('text_spacing=-1./60',
         'c1': Text_wArrow('text_spacing=-1./60',
                           (4, 3.5), (9, 3.2),
                           (4, 3.5), (9, 3.2),
                           fontsize=10, alignment='left'),
                           fontsize=10, alignment='left'),
@@ -145,12 +144,12 @@ def test_Rectangle():
     W = 4.0
     W = 4.0
 
 
     drawing_tool.set_coordinate_system(
     drawing_tool.set_coordinate_system(
-        xmin=0, xmax=2*W, ymin=old_div(-L,2), ymax=2*L,
+        xmin=0, xmax=2*W, ymin=-L/2, ymax=2*L,
         axis=True, instruction_file='tmp_Rectangle.py')
         axis=True, instruction_file='tmp_Rectangle.py')
     drawing_tool.set_linecolor('blue')
     drawing_tool.set_linecolor('blue')
     drawing_tool.set_grid(True)
     drawing_tool.set_grid(True)
 
 
-    xpos = old_div(W,2)
+    xpos = W/2
     r = Rectangle(lower_left_corner=(xpos,0), width=W, height=L)
     r = Rectangle(lower_left_corner=(xpos,0), width=W, height=L)
     r.draw()
     r.draw()
     r.draw_dimensions()
     r.draw_dimensions()
@@ -167,13 +166,13 @@ def test_Triangle():
     W = 4.0
     W = 4.0
 
 
     drawing_tool.set_coordinate_system(
     drawing_tool.set_coordinate_system(
-        xmin=0, xmax=2*W, ymin=old_div(-L,2), ymax=1.2*L,
+        xmin=0, xmax=2*W, ymin=-L/2, ymax=1.2*L,
         axis=True, instruction_file='tmp_Triangle.py')
         axis=True, instruction_file='tmp_Triangle.py')
     drawing_tool.set_linecolor('blue')
     drawing_tool.set_linecolor('blue')
     drawing_tool.set_grid(True)
     drawing_tool.set_grid(True)
 
 
     xpos = 1
     xpos = 1
-    t = Triangle(p1=(old_div(W,2),0), p2=(3*W/2,old_div(W,2)), p3=(4*W/5.,L))
+    t = Triangle(p1=(W/2,0), p2=(3*W/2,W/2), p3=(4*W/5.,L))
     t.draw()
     t.draw()
     t.draw_dimensions()
     t.draw_dimensions()
     drawing_tool.display('Triangle')
     drawing_tool.display('Triangle')
@@ -190,13 +189,13 @@ def test_Arc():
     W = 4.0
     W = 4.0
 
 
     drawing_tool.set_coordinate_system(
     drawing_tool.set_coordinate_system(
-        xmin=old_div(-W,2), xmax=W, ymin=old_div(-L,2), ymax=1.5*L,
+        xmin=-W/2, xmax=W, ymin=-L/2, ymax=1.5*L,
         axis=True, instruction_file='tmp_Arc.py')
         axis=True, instruction_file='tmp_Arc.py')
     drawing_tool.set_linecolor('blue')
     drawing_tool.set_linecolor('blue')
     drawing_tool.set_grid(True)
     drawing_tool.set_grid(True)
 
 
     center = point(0,0)
     center = point(0,0)
-    radius = old_div(L,2)
+    radius = L/2
     start_angle = 60
     start_angle = 60
     arc_angle = 45
     arc_angle = 45
     a = Arc(center, radius, start_angle, arc_angle)
     a = Arc(center, radius, start_angle, arc_angle)
@@ -209,11 +208,11 @@ def test_Arc():
         'start_angle':
         'start_angle':
         Arc_wText(
         Arc_wText(
             'start_angle', center, R1, start_angle=0,
             'start_angle', center, R1, start_angle=0,
-            arc_angle=start_angle, text_spacing=old_div(1,10.)),
+            arc_angle=start_angle, text_spacing=1/10.),
         'arc_angle':
         'arc_angle':
         Arc_wText(
         Arc_wText(
             'arc_angle', center, R2, start_angle=start_angle,
             'arc_angle', center, R2, start_angle=start_angle,
-            arc_angle=arc_angle, text_spacing=old_div(1,20.)),
+            arc_angle=arc_angle, text_spacing=1/20.),
         'r=0':
         'r=0':
         Line(center, center +
         Line(center, center +
              point(R*cos(radians(start_angle)),
              point(R*cos(radians(start_angle)),
@@ -225,8 +224,8 @@ def test_Arc():
         'r=start+arc_angle':
         'r=start+arc_angle':
         Line(center, center +
         Line(center, center +
              point(R, 0)).set_linestyle('dashed'),
              point(R, 0)).set_linestyle('dashed'),
-        'radius': Distance_wText(center, a(0), 'radius', text_spacing=old_div(1,40.)),
-        'center': Text('center', center-point(old_div(radius,10.), old_div(radius,10.))),
+        'radius': Distance_wText(center, a(0), 'radius', text_spacing=1/40.),
+        'center': Text('center', center-point(radius/10., radius/10.)),
         }
         }
     for dimension in a.dimensions:
     for dimension in a.dimensions:
         if dimension.startswith('r='):
         if dimension.startswith('r='):
@@ -267,7 +266,7 @@ def test_Spring():
     W = 2.0
     W = 2.0
 
 
     drawing_tool.set_coordinate_system(
     drawing_tool.set_coordinate_system(
-        xmin=0, xmax=7*W, ymin=old_div(-L,2), ymax=1.5*L,
+        xmin=0, xmax=7*W, ymin=-L/2, ymax=1.5*L,
         axis=True, instruction_file='tmp_Spring.py')
         axis=True, instruction_file='tmp_Spring.py')
     drawing_tool.set_linecolor('blue')
     drawing_tool.set_linecolor('blue')
     drawing_tool.set_grid(True)
     drawing_tool.set_grid(True)
@@ -275,13 +274,13 @@ def test_Spring():
     xpos = W
     xpos = W
     s1 = Spring((W,0), L, teeth=True)
     s1 = Spring((W,0), L, teeth=True)
     s1_title = Text('Default Spring',
     s1_title = Text('Default Spring',
-                    s1.geometric_features()['end'] + point(0,old_div(L,10)))
+                    s1.geometric_features()['end'] + point(0,L/10))
     s1.draw()
     s1.draw()
     s1_title.draw()
     s1_title.draw()
     #s1.draw_dimensions()
     #s1.draw_dimensions()
     xpos += 3*W
     xpos += 3*W
-    s2 = Spring(start=(xpos,0), length=L, width=old_div(W,2.),
-                bar_length=old_div(L,6.), teeth=False)
+    s2 = Spring(start=(xpos,0), length=L, width=W/2.,
+                bar_length=L/6., teeth=False)
     s2.draw()
     s2.draw()
     s2.draw_dimensions()
     s2.draw_dimensions()
     drawing_tool.display('Spring')
     drawing_tool.display('Spring')
@@ -323,7 +322,7 @@ def test_Dashpot():
     xpos = 0
     xpos = 0
 
 
     drawing_tool.set_coordinate_system(
     drawing_tool.set_coordinate_system(
-        xmin=xpos, xmax=xpos+5.5*W, ymin=old_div(-L,2), ymax=1.5*L,
+        xmin=xpos, xmax=xpos+5.5*W, ymin=-L/2, ymax=1.5*L,
         axis=True, instruction_file='tmp_Dashpot.py')
         axis=True, instruction_file='tmp_Dashpot.py')
     drawing_tool.set_linecolor('blue')
     drawing_tool.set_linecolor('blue')
     drawing_tool.set_grid(True)
     drawing_tool.set_grid(True)
@@ -332,15 +331,15 @@ def test_Dashpot():
     xpos = 1.5
     xpos = 1.5
     d1 = Dashpot(start=(xpos,0), total_length=L)
     d1 = Dashpot(start=(xpos,0), total_length=L)
     d1_title = Text('Dashpot (default)',
     d1_title = Text('Dashpot (default)',
-                    d1.geometric_features()['end'] + point(0,old_div(L,10)))
+                    d1.geometric_features()['end'] + point(0,L/10))
     d1.draw()
     d1.draw()
     d1_title.draw()
     d1_title.draw()
 
 
     # Dashpot for animation with fixed bar_length, dashpot_length and
     # Dashpot for animation with fixed bar_length, dashpot_length and
     # prescribed piston_pos
     # prescribed piston_pos
     xpos += 2.5*W
     xpos += 2.5*W
-    d2 = Dashpot(start=(xpos,0), total_length=1.2*L, width=old_div(W,2),
-                 bar_length=W, dashpot_length=old_div(L,2), piston_pos=2*W)
+    d2 = Dashpot(start=(xpos,0), total_length=1.2*L, width=W/2,
+                 bar_length=W, dashpot_length=L/2, piston_pos=2*W)
     d2.draw()
     d2.draw()
     d2.draw_dimensions()
     d2.draw_dimensions()
 
 
@@ -400,6 +399,202 @@ def test_Wavy():
     msg = 'expected=%s, computed=%s' % (expected, computed)
     msg = 'expected=%s, computed=%s' % (expected, computed)
     assert equal_dict(computed, expected), msg
     assert equal_dict(computed, expected), msg
 
 
+def test_beam():
+    L = 8.0
+    a = 3*L/4
+    b = L - a
+    H = 1.0
+    xpos = 0.0
+    ypos = 3.0
+
+    drawing_tool.set_coordinate_system(
+        xmin=-3, xmax=xpos+1.5*L,
+        ymin=0, ymax=ypos+5*H,
+        axis=False)
+    drawing_tool.set_linecolor('blue')
+    #drawing_tool.set_grid(True)
+    drawing_tool.set_fontsize(16)
+
+    A = point(xpos,ypos)
+
+    beam = Rectangle(A, L, H)
+
+    h = L/16  # size of support, clamped wall etc
+
+    clamped = Rectangle(A - point(h,0) - point(0,2*h), h,
+                        6*h).set_filled_curves(pattern='/')
+
+    load = ConstantBeamLoad(A + point(0,H), L, H)
+    load.set_linewidth(1).set_linecolor('black')
+    load_text = Text('$w$',
+                     load.geometric_features()['mid_top'] +
+                     point(0,h/2.))
+
+    B = A + point(a, 0)
+    C = B + point(b, 0)
+
+    support = SimplySupportedBeam(B, h)  # pt B is simply supported
+
+
+    R1 = Force(A-point(0,2*H), A, '$R_1$', text_spacing=1./50)
+    R1.set_linewidth(3).set_linecolor('black')
+    R2 = Force(B-point(0,2*H),
+               support.geometric_features()['mid_support'],
+               '$R_2$', text_spacing=1./50)
+    R2.set_linewidth(3).set_linecolor('black')
+    M1 = Moment('$M_1$', center=A + point(-H, H/2), radius=H/2,
+                left=True, text_spacing=1/30.)
+    M1.set_linecolor('black')
+
+    ab_level = point(0, 3*h)
+    a_dim = Distance_wText(A - ab_level, B - ab_level, '$a$')
+    b_dim = Distance_wText(B - ab_level, C - ab_level, '$b$')
+    dims = Composition({'a': a_dim, 'b': b_dim})
+    symbols = Composition(
+        {'R1': R1, 'R2': R2, 'M1': M1,
+         'w': load, 'w text': load_text,
+         'A': Text('$A$', A+point(0.7*h,-0.9*h)),
+         'B': Text('$B$',
+                   support.geometric_features()['mid_support']-
+                   point(1.25*h,0)),
+         'C': Text('$C$', C+point(h/2,-h/2))})
+
+    x_axis = Axis(A + point(L+h, H/2), 2*H, '$x$',).\
+             set_linecolor('black')
+    y_axis = Axis(A + point(0,H/2), 3.5*H, '$y$',
+                  label_alignment='left',
+                  rotation_angle=90).set_linecolor('black')
+    axes = Composition({'x axis': x_axis, 'y axis': y_axis})
+
+    annotations = Composition({'dims': dims, 'symbols': symbols,
+                               'axes': axes})
+    beam = Composition({'beam': beam, 'support': support,
+                        'clamped end': clamped, 'load': load})
+
+    def deflection(x, a, b, w):
+        import numpy as np
+        R1 = 5./8*w*a - 3*w*b**2/(4*a)
+        R2 = 3./8*w*a + w*b + 3*w*b**2/(4*a)
+        M1 = R1*a/3 - w*a**2/12
+        y = -(M1/2.)*x**2 + 1./6*R1*x**3 - w/24.*x**4 + \
+            1./6*R2*np.where(x > a, 1, 0)*(x-a)**3
+        return y
+
+    x = linspace(0, L, 101)
+    y = deflection(x, a, b, w=1.0)
+    y /= abs(y.max() - y.min())
+    y += ypos + H/2
+
+    elastic_line = Curve(x, y).\
+                   set_linecolor('red').\
+                   set_linestyle('dashed').\
+                   set_linewidth(3)
+
+    beam.draw()
+    drawing_tool.display()
+
+    import time
+    time.sleep(1.5)
+
+    annotations.draw()
+    drawing_tool.display()
+    time.sleep(1.5)
+
+    elastic_line.draw()
+    drawing_tool.display()
+    #beam.draw_dimensions()
+    drawing_tool.savefig('tmp_beam')
+
+    all = Composition({'beam': beam, 'text': annotations,
+                       'deflection': elastic_line})
+    expected = {
+        'beam': {
+            'load': {
+                u'box': {
+                    u'rectangle': "5 (x,y) coords linecolor=u'k' linewidth=1",},
+                u'arrow9': {u'arrow': {
+                    u'line': "2 (x,y) coords linecolor=u'k' linewidth=1 arrow=u'->'",},},
+                u'arrow8': {u'arrow': {
+                    u'line': "2 (x,y) coords linecolor=u'k' linewidth=1 arrow=u'->'",},},
+                u'arrow7': {u'arrow': {
+                    u'line': "2 (x,y) coords linecolor=u'k' linewidth=1 arrow=u'->'",},},
+                u'arrow6': {u'arrow': {
+                    u'line': "2 (x,y) coords linecolor=u'k' linewidth=1 arrow=u'->'",},},
+                u'arrow5': {u'arrow': {
+                    u'line': "2 (x,y) coords linecolor=u'k' linewidth=1 arrow=u'->'",},},
+                u'arrow4': {u'arrow': {
+                    u'line': "2 (x,y) coords linecolor=u'k' linewidth=1 arrow=u'->'",},},
+                u'arrow3': {u'arrow': {
+                    u'line': "2 (x,y) coords linecolor=u'k' linewidth=1 arrow=u'->'",},},
+                u'arrow2': {u'arrow': {
+                    u'line': "2 (x,y) coords linecolor=u'k' linewidth=1 arrow=u'->'",},},
+                u'arrow1': {u'arrow': {
+                    u'line': "2 (x,y) coords linecolor=u'k' linewidth=1 arrow=u'->'",},},
+                u'arrow0': {u'arrow': {
+                    u'line': "2 (x,y) coords linecolor=u'k' linewidth=1 arrow=u'->'",},},},
+            'beam': {
+                u'rectangle': "5 (x,y) coords",},
+            'support': {
+                u'triangle': {u'triangle': "4 (x,y) coords",},
+                u'rectangle': {u'rectangle': "5 (x,y) coords fillcolor=u'' fillpattern=u'/'",},},
+            'clamped end': {
+                u'rectangle': "5 (x,y) coords fillcolor=u'' fillpattern='/'",},},
+        'deflection': "101 (x,y) coords linecolor='red' linewidth=3 linestyle='dashed'",
+        'text': {
+            'symbols': {
+                'A': "Text at (0.35,2.55)",
+                'w': {u'box': {u'rectangle': "5 (x,y) coords linecolor=u'k' linewidth=1",},
+                      u'arrow9': {u'arrow': {
+                          u'line': "2 (x,y) coords linecolor=u'k' linewidth=1 arrow=u'->'",},},
+                      u'arrow8': {u'arrow': {
+                          u'line': "2 (x,y) coords linecolor=u'k' linewidth=1 arrow=u'->'",},},
+                      u'arrow7': {u'arrow': {
+                          u'line': "2 (x,y) coords linecolor=u'k' linewidth=1 arrow=u'->'",},},
+                      u'arrow6': {u'arrow': {
+                          u'line': "2 (x,y) coords linecolor=u'k' linewidth=1 arrow=u'->'",},},
+                      u'arrow5': {u'arrow': {
+                          u'line': "2 (x,y) coords linecolor=u'k' linewidth=1 arrow=u'->'",},},
+                      u'arrow4': {u'arrow': {
+                          u'line': "2 (x,y) coords linecolor=u'k' linewidth=1 arrow=u'->'",},},
+                      u'arrow3': {u'arrow': {
+                          u'line': "2 (x,y) coords linecolor=u'k' linewidth=1 arrow=u'->'",},},
+                      u'arrow2': {u'arrow': {
+                          u'line': "2 (x,y) coords linecolor=u'k' linewidth=1 arrow=u'->'",},},
+                      u'arrow1': {u'arrow': {
+                          u'line': "2 (x,y) coords linecolor=u'k' linewidth=1 arrow=u'->'",},},
+                      u'arrow0': {u'arrow': {
+                          u'line': "2 (x,y) coords linecolor=u'k' linewidth=1 arrow=u'->'",},},},
+                'C': "Text at (8.25,2.75)",
+                'B': "Text at (5.375,2.275)",
+                'M1': {
+                    u'text': "Text at (-2,3.5)",
+                    u'arc': {u'arc': "181 (x,y) coords linecolor=u'k' arrow=u'->'",},},
+                'R1': {
+                    u'text': "Text at (0,0.49)",
+                    u'arrow': {u'line': "2 (x,y) coords linecolor=u'k' linewidth=3 arrow=u'->'",},},
+                'R2': {
+                    u'text': "Text at (6,0.49)",
+                    u'arrow': {u'line': "2 (x,y) coords linecolor=u'k' linewidth=3 arrow=u'->'",},},
+                'w text': "Text at (4,5.25)",},
+            'dims': {
+                'a': {
+                    u'text': "Text at (3,1.75)",
+                    u'arrow': {u'arrow': {
+                        u'line': "2 (x,y) coords linecolor=u'k' linewidth=1 arrow=u'<->'",},},},
+                'b': {
+                    u'text': "Text at (7,1.75)",
+                    u'arrow': {u'arrow': {
+                        u'line': "2 (x,y) coords linecolor=u'k' linewidth=1 arrow=u'<->'",},},},},
+            'axes': {'x axis': {
+                u'arrow': {u'head left': {u'line': "2 (x,y) coords linecolor=u'k' linestyle=u'solid'",}, u'line': {u'line': "2 (x,y) coords linecolor=u'k'",}, u'head right': {u'line': "2 (x,y) coords linecolor=u'k' linestyle=u'solid'",},}, u'label': "Text at (10.8333,3.5)",},
+                     'y axis': {
+                u'arrow': {u'head left': {u'line': "2 (x,y) coords linecolor=u'k' linestyle=u'solid'",}, u'line': {u'line': "2 (x,y) coords linecolor=u'k'",}, u'head right': {u'line': "2 (x,y) coords linecolor=u'k' linestyle=u'solid'",},}, u'label': "Text at (2.34724e-16,7.33333)",},
+                     },
+            },
+        }
+    computed = eval(repr(all))
+    msg = 'expected=%s, computed=%s' % (expected, computed)
+    assert equal_dict(computed, expected), msg
 
 
 def diff_files(files1, files2, mode='HTML'):
 def diff_files(files1, files2, mode='HTML'):
     import difflib, time
     import difflib, time