Hans Petter Langtangen 9 年之前
父节点
当前提交
fb48ec73f0

+ 615 - 0
doc/pub/tutorial/._pysketcher004.html

@@ -0,0 +1,615 @@
+<!--
+Automatically generated HTML file from DocOnce source
+(https://github.com/hplgit/doconce/)
+-->
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<meta name="generator" content="DocOnce: https://github.com/hplgit/doconce/" />
+<meta name="description" content="Using Pysketcher to Create Principal Sketches of Physics Problems">
+<meta name="keywords" content="tree data structure,recursive function calls">
+
+<title>Using Pysketcher to Create Principal Sketches of Physics Problems</title>
+
+<!-- Bootstrap style: bootswatch_readable -->
+<link href="http://netdna.bootstrapcdn.com/bootswatch/3.1.1/readable/bootstrap.min.css" rel="stylesheet">
+<!-- not necessary
+<link href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
+-->
+
+<style type="text/css">
+
+/* Add scrollbar to dropdown menus in bootstrap navigation bar */
+.dropdown-menu {
+   height: auto;
+   max-height: 400px;
+   overflow-x: hidden;
+}
+</style>
+
+
+</head>
+
+<!-- tocinfo
+{'highest level': 1,
+ 'sections': [('A first glimpse of Pysketcher', 1, None, '___sec0'),
+              ('Basic construction of sketches', 2, None, '___sec1'),
+              ('Basic drawing', 3, None, '___sec2'),
+              ('Groups of objects', 3, None, '___sec3'),
+              ('Changing line styles and colors', 3, None, '___sec4'),
+              ('The figure composition as an object hierarchy',
+               3,
+               None,
+               '___sec5'),
+              ('Animation: translating the vehicle', 3, None, '___sec6'),
+              ('Animation: rolling the wheels',
+               3,
+               'sketcher:vehicle1:anim',
+               'sketcher:vehicle1:anim'),
+              ('A simple pendulum',
+               1,
+               'sketcher:ex:pendulum',
+               'sketcher:ex:pendulum'),
+              ('The basic physics sketch',
+               2,
+               'sketcher:ex:pendulum:basic',
+               'sketcher:ex:pendulum:basic'),
+              ('The body diagram', 2, None, '___sec10'),
+              ('Animated body diagram',
+               2,
+               'sketcher:ex:pendulum:anim',
+               'sketcher:ex:pendulum:anim'),
+              ('Function for drawing the body diagram', 3, None, '___sec12'),
+              ('Equations for the motion and forces', 3, None, '___sec13'),
+              ('Numerical solution', 3, None, '___sec14'),
+              ('Animation', 3, None, '___sec15'),
+              ('Basic shapes', 1, None, '___sec16'),
+              ('Axis', 2, None, '___sec17'),
+              ('Distance with text', 2, None, '___sec18'),
+              ('Rectangle', 2, None, '___sec19'),
+              ('Triangle', 2, None, '___sec20'),
+              ('Arc', 2, None, '___sec21'),
+              ('Spring', 2, None, '___sec22'),
+              ('Dashpot', 2, None, '___sec23'),
+              ('Wavy', 2, None, '___sec24'),
+              ('Stochastic curves', 2, None, '___sec25'),
+              ('Inner workings of the Pysketcher tool', 1, None, '___sec26'),
+              ('Example of classes for geometric objects',
+               2,
+               None,
+               '___sec27'),
+              ('Simple geometric objects', 3, None, '___sec28'),
+              ('Class curve', 3, None, '___sec29'),
+              ('Compound geometric objects', 3, None, '___sec30'),
+              ('Adding functionality via recursion', 2, None, '___sec31'),
+              ('Basic principles of recursion', 3, None, '___sec32'),
+              ('Explaining recursion', 3, None, '___sec33'),
+              ('Scaling, translating, and rotating a figure',
+               2,
+               'sketcher:scaling',
+               'sketcher:scaling'),
+              ('Scaling', 3, None, '___sec35'),
+              ('Translation', 3, None, '___sec36'),
+              ('Rotation', 3, None, '___sec37')]}
+end of tocinfo -->
+
+<body>
+
+
+
+<script type="text/x-mathjax-config">
+MathJax.Hub.Config({
+  TeX: {
+     equationNumbers: {  autoNumber: "none"  },
+     extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
+  }
+});
+</script>
+<script type="text/javascript"
+ src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
+</script>
+
+<!-- newcommands.tex -->
+$$
+\newcommand{\half}{\frac{1}{2}}
+\newcommand{\tp}{\thinspace .}
+\newcommand{\rpos}{\boldsymbol{r}}
+\newcommand{\ii}{\boldsymbol{i}}
+\newcommand{\jj}{\boldsymbol{j}}
+\newcommand{\ir}{\boldsymbol{i}_r}
+\newcommand{\ith}{\boldsymbol{i}_{\theta}}
+$$
+
+
+
+
+    
+<!-- Bootstrap navigation bar -->
+<div class="navbar navbar-default navbar-fixed-top">
+  <div class="navbar-header">
+    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
+      <span class="icon-bar"></span>
+      <span class="icon-bar"></span>
+      <span class="icon-bar"></span>
+    </button>
+    <a class="navbar-brand" href="pysketcher.html">Using Pysketcher to Create Principal Sketches of Physics Problems</a>
+  </div>
+
+  <div class="navbar-collapse collapse navbar-responsive-collapse">
+    <ul class="nav navbar-nav navbar-right">
+      <li class="dropdown">
+        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
+        <ul class="dropdown-menu">
+     <!-- navigation toc: --> <li><a href="._pysketcher002.html#___sec0" style="font-size: 80%;"><b>A first glimpse of Pysketcher</b></a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher002.html#___sec1" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Basic construction of sketches</a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher002.html#___sec2" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Basic drawing</a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher002.html#___sec3" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Groups of objects</a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher002.html#___sec4" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Changing line styles and colors</a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher002.html#___sec5" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The figure composition as an object hierarchy</a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher002.html#___sec6" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Animation: translating the vehicle</a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher002.html#sketcher:vehicle1:anim" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Animation: rolling the wheels</a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher003.html#sketcher:ex:pendulum" style="font-size: 80%;"><b>A simple pendulum</b></a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher003.html#sketcher:ex:pendulum:basic" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;The basic physics sketch</a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher003.html#___sec10" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;The body diagram</a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher003.html#sketcher:ex:pendulum:anim" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Animated body diagram</a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher003.html#___sec12" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Function for drawing the body diagram</a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher003.html#___sec13" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Equations for the motion and forces</a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher003.html#___sec14" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Numerical solution</a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher003.html#___sec15" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Animation</a></li>
+     <!-- navigation toc: --> <li><a href="#___sec16" style="font-size: 80%;"><b>Basic shapes</b></a></li>
+     <!-- navigation toc: --> <li><a href="#___sec17" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Axis</a></li>
+     <!-- navigation toc: --> <li><a href="#___sec18" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Distance with text</a></li>
+     <!-- navigation toc: --> <li><a href="#___sec19" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Rectangle</a></li>
+     <!-- navigation toc: --> <li><a href="#___sec20" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Triangle</a></li>
+     <!-- navigation toc: --> <li><a href="#___sec21" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Arc</a></li>
+     <!-- navigation toc: --> <li><a href="#___sec22" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Spring</a></li>
+     <!-- navigation toc: --> <li><a href="#___sec23" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Dashpot</a></li>
+     <!-- navigation toc: --> <li><a href="#___sec24" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Wavy</a></li>
+     <!-- navigation toc: --> <li><a href="#___sec25" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Stochastic curves</a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher005.html#___sec26" style="font-size: 80%;"><b>Inner workings of the Pysketcher tool</b></a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher005.html#___sec27" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Example of classes for geometric objects</a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher005.html#___sec28" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Simple geometric objects</a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher005.html#___sec29" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Class curve</a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher005.html#___sec30" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Compound geometric objects</a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher005.html#___sec31" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Adding functionality via recursion</a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher005.html#___sec32" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Basic principles of recursion</a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher005.html#___sec33" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Explaining recursion</a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher005.html#sketcher:scaling" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Scaling, translating, and rotating a figure</a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher005.html#___sec35" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Scaling</a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher005.html#___sec36" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Translation</a></li>
+     <!-- navigation toc: --> <li><a href="._pysketcher005.html#___sec37" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Rotation</a></li>
+
+        </ul>
+      </li>
+    </ul>
+  </div>
+</div>
+</div> <!-- end of navigation bar -->
+
+<div class="container">
+
+<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
+
+<a name="part0004"></a>
+<!-- !split -->
+
+<h1 id="___sec16">Basic shapes </h1>
+
+<p>
+This section presents many of the basic shapes in Pysketcher:
+<code>Axis</code>, <code>Distance_wText</code>, <code>Rectangle</code>, 	<code>Triangle</code>, <code>Arc</code>,
+<code>Spring</code>, <code>Dashpot</code>, and <code>Wavy</code>.
+Each shape is demonstrated with a figure and a
+unit test that shows how the figure is constructed in Python code.
+These demos rely heavily on the method <code>draw_dimensions</code> in
+the shape classes, which annotates the basic drawing of the shape
+with the various geometric parameters that govern the shape.
+
+<h2 id="___sec17">Axis </h2>
+
+<p>
+The <code>Axis</code> object gives the possibility draw a single axis to
+notify a coordinate system. Here is an example where we
+draw \( x \) and \( y \) axis of three coordinate systems of different
+rotation:
+
+<p>
+<br />
+<br />
+
+<p>
+<center><p><img src="fig-tut/Axis.png" align="bottom" width=500></p></center>
+
+<p>
+<br />
+<br />
+
+<p>
+The corresponding code looks like this:
+
+<p>
+
+<!-- code=python (!bc pycod) typeset with pygments style "default" -->
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">test_Axis</span>():
+    drawing_tool<span style="color: #666666">.</span>set_coordinate_system(
+        xmin<span style="color: #666666">=0</span>, xmax<span style="color: #666666">=15</span>, ymin<span style="color: #666666">=-7</span>, ymax<span style="color: #666666">=8</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_Axis.py&#39;</span>)
+    <span style="color: #408080; font-style: italic"># Draw normal x and y axis with origin at (7.5, 2)</span>
+    <span style="color: #408080; font-style: italic"># in the coordinate system of the sketch: [0,15]x[-7,8]</span>
+    x_axis <span style="color: #666666">=</span> Axis((<span style="color: #666666">7.5</span>,<span style="color: #666666">2</span>), <span style="color: #666666">5</span>, <span style="color: #BA2121">&#39;x&#39;</span>, rotation_angle<span style="color: #666666">=0</span>)
+    y_axis <span style="color: #666666">=</span> Axis((<span style="color: #666666">7.5</span>,<span style="color: #666666">2</span>), <span style="color: #666666">5</span>, <span style="color: #BA2121">&#39;y&#39;</span>, rotation_angle<span style="color: #666666">=90</span>)
+    system <span style="color: #666666">=</span> Composition({<span style="color: #BA2121">&#39;x axis&#39;</span>: x_axis, <span style="color: #BA2121">&#39;y axis&#39;</span>: y_axis})
+    system<span style="color: #666666">.</span>draw()
+    drawing_tool<span style="color: #666666">.</span>display()
+
+    <span style="color: #408080; font-style: italic"># Rotate this system 40 degrees counter clockwise</span>
+    <span style="color: #408080; font-style: italic"># and draw it with dashed lines</span>
+    system<span style="color: #666666">.</span>set_linestyle(<span style="color: #BA2121">&#39;dashed&#39;</span>)
+    system<span style="color: #666666">.</span>rotate(<span style="color: #666666">40</span>, (<span style="color: #666666">7.5</span>,<span style="color: #666666">2</span>))
+    system<span style="color: #666666">.</span>draw()
+    drawing_tool<span style="color: #666666">.</span>display()
+
+    <span style="color: #408080; font-style: italic"># Rotate this system another 220 degrees and show</span>
+    <span style="color: #408080; font-style: italic"># with dotted lines</span>
+    system<span style="color: #666666">.</span>set_linestyle(<span style="color: #BA2121">&#39;dotted&#39;</span>)
+    system<span style="color: #666666">.</span>rotate(<span style="color: #666666">220</span>, (<span style="color: #666666">7.5</span>,<span style="color: #666666">2</span>))
+    system<span style="color: #666666">.</span>draw()
+    drawing_tool<span style="color: #666666">.</span>display()
+
+    drawing_tool<span style="color: #666666">.</span>display(<span style="color: #BA2121">&#39;Axis&#39;</span>)
+</pre></div>
+
+<h2 id="___sec18">Distance with text </h2>
+
+<p>
+The object <code>Distance_wText</code> is used to display an arrow, to indicate
+a distance in a sketch, with an additional text in the middle of the arrow.
+
+<p>
+The figure
+
+<p>
+<br />
+<br />
+
+<p>
+<center><p><img src="fig-tut/Distance_wText.png" align="bottom" width=500></p></center>
+
+<p>
+<br />
+<br />
+
+<p>
+was produced by this code:
+
+<p>
+
+<!-- code=python (!bc pycod) typeset with pygments style "default" -->
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">test_Distance_wText</span>():
+    drawing_tool<span style="color: #666666">.</span>set_coordinate_system(
+        xmin<span style="color: #666666">=0</span>, xmax<span style="color: #666666">=10</span>, ymin<span style="color: #666666">=0</span>, ymax<span style="color: #666666">=6</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_Distance_wText.py&#39;</span>)
+
+    fontsize<span style="color: #666666">=14</span>
+    t <span style="color: #666666">=</span> <span style="color: #BA2121">r&#39;$ 2\pi R^2 $&#39;</span>  <span style="color: #408080; font-style: italic"># sample text</span>
+    examples <span style="color: #666666">=</span> Composition({
+        <span style="color: #BA2121">&#39;a0&#39;</span>: Distance_wText((<span style="color: #666666">4</span>,<span style="color: #666666">5</span>), (<span style="color: #666666">8</span>, <span style="color: #666666">5</span>), t, fontsize),
+        <span style="color: #BA2121">&#39;a6&#39;</span>: Distance_wText((<span style="color: #666666">4</span>,<span style="color: #666666">5</span>), (<span style="color: #666666">4</span>, <span style="color: #666666">4</span>), t, fontsize),
+        <span style="color: #BA2121">&#39;a1&#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">4.5</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;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">=-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,
+                             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: #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>),
+        <span style="color: #BA2121">&#39;c2&#39;</span>: Text_wArrow(<span style="color: #BA2121">&#39;text_spacing=-1./40, alignment=&quot;right&quot;&#39;</span>,
+                          (<span style="color: #666666">4</span>, <span style="color: #666666">0.5</span>), (<span style="color: #666666">9</span>, <span style="color: #666666">1.2</span>),
+                          fontsize<span style="color: #666666">=10</span>, alignment<span style="color: #666666">=</span><span style="color: #BA2121">&#39;left&#39;</span>),
+        })
+    examples<span style="color: #666666">.</span>draw()
+    drawing_tool<span style="color: #666666">.</span>display(<span style="color: #BA2121">&#39;Distance_wText and text positioning&#39;</span>)
+</pre></div>
+<p>
+Note the use of <code>Text_wArrow</code> to write an explaining text with an
+associated arrow, here used to explain how
+the <code>text_spacing</code> and <code>alignment</code> arguments can be used to adjust
+the appearance of the text that goes with the distance arrow.
+
+<h2 id="___sec19">Rectangle </h2>
+
+<p>
+<center><p><img src="fig-tut/Rectangle.png" align="bottom" width=500></p></center>
+
+<p>
+<br />
+<br />
+
+<p>
+The above figure can be produced by the following code.
+
+<p>
+
+<!-- code=python (!bc pycod) typeset with pygments style "default" -->
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">test_Rectangle</span>():
+    L <span style="color: #666666">=</span> <span style="color: #666666">3.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(
+        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>)
+    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>)
+
+    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>draw()
+    r<span style="color: #666666">.</span>draw_dimensions()
+    drawing_tool<span style="color: #666666">.</span>display(<span style="color: #BA2121">&#39;Rectangle&#39;</span>)
+</pre></div>
+<p>
+Note that the <code>draw_dimension</code> method adds explanation of dimensions and various
+important argument in the construction of a shape. It adapts the annotations
+to the geometry of the current shape.
+
+<h2 id="___sec20">Triangle </h2>
+
+<p>
+<center><p><img src="fig-tut/Triangle.png" align="bottom" width=500></p></center>
+
+<p>
+<br />
+<br />
+
+<p>
+The code below produces the figure.
+
+<p>
+
+<!-- code=python (!bc pycod) typeset with pygments style "default" -->
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">test_Triangle</span>():
+    L <span style="color: #666666">=</span> <span style="color: #666666">3.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(
+        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>)
+    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>)
+
+    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>(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_dimensions()
+    drawing_tool<span style="color: #666666">.</span>display(<span style="color: #BA2121">&#39;Triangle&#39;</span>)
+</pre></div>
+<p>
+Here, the <code>draw_dimension</code> method writes the name of the corners at the
+position of the corners, which does not always look nice (the present figure
+is an example). For a high-quality sketch one would add some spacing
+to the location of the p1, p2, and even p3 texts.
+
+<h2 id="___sec21">Arc </h2>
+
+<p>
+<center><p><img src="fig-tut/Arc.png" align="bottom" width=400></p></center>
+
+<p>
+<br />
+<br />
+
+<p>
+An arc like the one above is produced by
+
+<p>
+
+<!-- code=python (!bc pycod) typeset with pygments style "default" -->
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">test_Arc</span>():
+    L <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(
+        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>)
+    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>)
+
+    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> L<span style="color: #666666">/2</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>
+    a <span style="color: #666666">=</span> Arc(center, radius, start_angle, arc_angle)
+    a<span style="color: #666666">.</span>draw()
+
+    R1 <span style="color: #666666">=</span> <span style="color: #666666">1.25*</span>radius
+    R2 <span style="color: #666666">=</span> <span style="color: #666666">1.5*</span>radius
+    R <span style="color: #666666">=</span> <span style="color: #666666">2*</span>radius
+    a<span style="color: #666666">.</span>dimensions <span style="color: #666666">=</span> {
+        <span style="color: #BA2121">&#39;start_angle&#39;</span>:
+        Arc_wText(
+            <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">=1/10.</span>),
+        <span style="color: #BA2121">&#39;arc_angle&#39;</span>:
+        Arc_wText(
+            <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">=1/20.</span>),
+        <span style="color: #BA2121">&#39;r=0&#39;</span>:
+        Line(center, center <span style="color: #666666">+</span>
+             point(R<span style="color: #666666">*</span>cos(radians(start_angle)),
+                   R<span style="color: #666666">*</span>sin(radians(start_angle)))),
+        <span style="color: #BA2121">&#39;r=start_angle&#39;</span>:
+        Line(center, center <span style="color: #666666">+</span>
+             point(R<span style="color: #666666">*</span>cos(radians(start_angle<span style="color: #666666">+</span>arc_angle)),
+                   R<span style="color: #666666">*</span>sin(radians(start_angle<span style="color: #666666">+</span>arc_angle)))),
+        <span style="color: #BA2121">&#39;r=start+arc_angle&#39;</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>),
+        <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">if</span> dimension<span style="color: #666666">.</span>startswith(<span style="color: #BA2121">&#39;r=&#39;</span>):
+            dim <span style="color: #666666">=</span> a<span style="color: #666666">.</span>dimensions[dimension]
+            dim<span style="color: #666666">.</span>set_linestyle(<span style="color: #BA2121">&#39;dashed&#39;</span>)
+            dim<span style="color: #666666">.</span>set_linewidth(<span style="color: #666666">1</span>)
+            dim<span style="color: #666666">.</span>set_linecolor(<span style="color: #BA2121">&#39;black&#39;</span>)
+
+    a<span style="color: #666666">.</span>draw_dimensions()
+    drawing_tool<span style="color: #666666">.</span>display(<span style="color: #BA2121">&#39;Arc&#39;</span>)
+</pre></div>
+
+<h2 id="___sec22">Spring </h2>
+
+<p>
+<center><p><img src="fig-tut/Spring.png" align="bottom" width=800></p></center>
+
+<p>
+<br />
+<br />
+
+<p>
+The code for making these two springs goes like this:
+
+<p>
+
+<!-- code=python (!bc pycod) typeset with pygments style "default" -->
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">test_Spring</span>():
+    L <span style="color: #666666">=</span> <span style="color: #666666">5.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(
+        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>)
+    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>)
+
+    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_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>,L<span style="color: #666666">/10</span>))
+    s1<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>
+    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>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_dimensions()
+    drawing_tool<span style="color: #666666">.</span>display(<span style="color: #BA2121">&#39;Spring&#39;</span>)
+</pre></div>
+
+<h2 id="___sec23">Dashpot </h2>
+
+<p>
+<center><p><img src="fig-tut/Dashpot.png" align="bottom" width=600></p></center>
+
+<p>
+<br />
+<br />
+
+<p>
+This dashpot is produced by
+
+<p>
+
+<!-- code=python (!bc pycod) typeset with pygments style "default" -->
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">test_Dashpot</span>():
+    L <span style="color: #666666">=</span> <span style="color: #666666">5.0</span>
+    W <span style="color: #666666">=</span> <span style="color: #666666">2.0</span>
+    xpos <span style="color: #666666">=</span> <span style="color: #666666">0</span>
+
+    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>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>)
+    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>)
+
+    <span style="color: #408080; font-style: italic"># Default (simple) dashpot</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_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>,L<span style="color: #666666">/10</span>))
+    d1<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"># prescribed piston_pos</span>
+    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>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_dimensions()
+
+    drawing_tool<span style="color: #666666">.</span>display(<span style="color: #BA2121">&#39;Dashpot&#39;</span>)
+</pre></div>
+
+<h2 id="___sec24">Wavy </h2>
+
+<p>
+Looks strange. Fix x axis.
+
+<h2 id="___sec25">Stochastic curves </h2>
+
+<p>
+The <code>StochasticWavyCurve</code> object offers three precomputed
+graphics that have a random variation:
+
+<p>
+<br />
+<br />
+
+<p>
+<center><p><img src="fig-tut/StochasticWavyCurve.png" align="bottom" width=600></p></center>
+
+<p>
+<br />
+<br />
+
+<p>
+The usage is simple. The construction
+
+<p>
+
+<!-- code=python (!bc pycod) typeset with pygments style "default" -->
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%">curve <span style="color: #666666">=</span> StochasticWavyCurve(curve_no<span style="color: #666666">=1</span>, percentage<span style="color: #666666">=40</span>)
+</pre></div>
+<p>
+picks the second curve (the three are numbered 0, 1, and 2),
+and the first 40% of that curve. In case one desires another extent
+of the axis, one can just scale the coordinates directly as these
+are stored in the arrays <code>curve.x[curve_no]</code> and
+<code>curve.y[curve_no]</code>.
+
+<p>
+<p>
+<!-- navigation buttons at the bottom of the page -->
+<ul class="pagination">
+<li><a href="._pysketcher003.html">&laquo;</a></li>
+  <li><a href="._pysketcher000.html">1</a></li>
+  <li><a href="._pysketcher001.html">2</a></li>
+  <li><a href="._pysketcher002.html">3</a></li>
+  <li><a href="._pysketcher003.html">4</a></li>
+  <li class="active"><a href="._pysketcher004.html">5</a></li>
+  <li><a href="._pysketcher005.html">6</a></li>
+  <li><a href="._pysketcher005.html">&raquo;</a></li>
+</ul>
+<!-- ------------------- end of main content --------------- -->
+
+</div>  <!-- end container -->
+<!-- include javascript, jQuery *first* -->
+<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
+<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
+
+<!-- Bootstrap footer
+<footer>
+<a href="http://..."><img width="250" align=right src="http://..."></a>
+</footer>
+-->
+
+
+</body>
+</html>
+    
+

文件差异内容过多而无法显示
+ 980 - 0
doc/pub/tutorial/._pysketcher005.html


二进制
doc/pub/tutorial/html/_images/pendulum1.png


二进制
doc/pub/tutorial/html/_images/pendulum1_wgrid.png


二进制
doc/pub/tutorial/html/_images/pendulum5_wgrid.png


+ 6 - 6
examples/pendulum1.py

@@ -52,10 +52,10 @@ fig.draw()
 drawing_tool.display()
 drawing_tool.savefig('tmp_pendulum1')
 
-# Draw body diagram in several different versions
+# Draw free body diagram in several different versions
 # (note that we build body_diagram, erase and draw,
 # add elements to body_diagram, erase and draw, and so on)
-input('Press Return to make body diagram: ')
+input('Press Return to make free body diagram: ')
 
 drawing_tool.erase()
 
@@ -84,17 +84,17 @@ body_diagram = Composition(
      'body': mass, 'm': mass_symbol})
 
 body_diagram.draw()
-#drawing_tool.display('Body diagram')
+#drawing_tool.display('Free body diagram')
 drawing_tool.savefig('tmp_pendulum2')
 
 drawing_tool.adjust_coordinate_system(body_diagram.minmax_coordinates(), 90)
-#drawing_tool.display('Body diagram')
+#drawing_tool.display('Free body diagram')
 drawing_tool.savefig('tmp_pendulum3')
 
 drawing_tool.erase()
 body_diagram['air'] = air_force
 body_diagram.draw()
-#drawing_tool.display('Body diagram')
+#drawing_tool.display('Free body diagram')
 drawing_tool.savefig('tmp_pendulum4')
 
 drawing_tool.erase()
@@ -111,7 +111,7 @@ body_diagram['ith'] = ith
 body_diagram['origin'] = x0y0
 
 body_diagram.draw()
-#drawing_tool.display('Body diagram')
+#drawing_tool.display('Free body diagram')
 drawing_tool.savefig('tmp_pendulum5')
 
 input()

+ 2 - 2
examples/pendulum2.py

@@ -1,6 +1,6 @@
 """
 Modified version of pendulum1.py:
-A function draws the body diagram, given the angle.
+A function draws the free body diagram, given the angle.
 This function can be coupled to a numerical solver
 for the motion. Videos of the motion are made.
 """
@@ -105,7 +105,7 @@ def pendulum(theta, S, mg, drag, t, time_level):
 
     drawing_tool.erase()
     body_diagram.draw(verbose=0)
-    #drawing_tool.display('Body diagram')
+    #drawing_tool.display('Free body diagram')
     drawing_tool.savefig('tmp_%04d.png' % time_level, crop=False)
     # No cropping: otherwise movies will be very strange