._pysketcher002.html 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. <!--
  2. Automatically generated HTML file from DocOnce source
  3. (https://github.com/hplgit/doconce/)
  4. -->
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  8. <meta name="generator" content="DocOnce: https://github.com/hplgit/doconce/" />
  9. <meta name="description" content="Using Pysketcher to Create Principal Sketches of Physics Problems">
  10. <meta name="keywords" content="tree data structure,recursive function calls">
  11. <title>Using Pysketcher to Create Principal Sketches of Physics Problems</title>
  12. <style type="text/css">
  13. /* blueish style */
  14. /* Color definitions: http://www.december.com/html/spec/color0.html
  15. CSS examples: http://www.w3schools.com/css/css_examples.asp */
  16. body {
  17. margin-top: 1.0em;
  18. background-color: #ffffff;
  19. font-family: Helvetica, Arial, FreeSans, san-serif;
  20. color: #000000;
  21. }
  22. h1 { font-size: 1.8em; color: #1e36ce; }
  23. h2 { font-size: 1.6em; color: #1e36ce; }
  24. h3 { font-size: 1.4em; color: #1e36ce; }
  25. a { color: #1e36ce; text-decoration:none; }
  26. tt { font-family: "Courier New", Courier; }
  27. /* pre style removed because it will interfer with pygments */
  28. p { text-indent: 0px; }
  29. hr { border: 0; width: 80%; border-bottom: 1px solid #aaa}
  30. p.caption { width: 80%; font-style: normal; text-align: left; }
  31. hr.figure { border: 0; width: 80%; border-bottom: 1px solid #aaa}
  32. div { text-align: justify; text-justify: inter-word; }
  33. </style>
  34. </head>
  35. <!-- tocinfo
  36. {'highest level': 1,
  37. 'sections': [(' A First Glimpse of Pysketcher ', 1, None, '___sec0'),
  38. (' Basic Construction of Sketches ', 2, None, '___sec1'),
  39. (' Basic Drawing ', 3, None, '___sec2'),
  40. (' Groups of Objects ', 3, None, '___sec3'),
  41. (' Changing Line Styles and Colors ', 3, None, '___sec4'),
  42. (' The Figure Composition as an Object Hierarchy ',
  43. 3,
  44. None,
  45. '___sec5'),
  46. (' Animation: Translating the Vehicle ', 3, None, '___sec6'),
  47. (' Animation: Rolling the Wheels ',
  48. 3,
  49. 'sketcher:vehicle1:anim',
  50. 'sketcher:vehicle1:anim'),
  51. (' Basic Shapes ', 1, None, '___sec8'),
  52. (' Axis ', 2, None, '___sec9'),
  53. (' Distance with Text ', 2, None, '___sec10'),
  54. (' Rectangle ', 2, None, '___sec11'),
  55. (' Triangle ', 2, None, '___sec12'),
  56. (' Arc ', 2, None, '___sec13'),
  57. (' Spring ', 2, None, '___sec14'),
  58. (' Dashpot ', 2, None, '___sec15'),
  59. (' Wavy ', 2, None, '___sec16'),
  60. (' Stochastic curves ', 2, None, '___sec17'),
  61. (' Inner Workings of the Pysketcher Tool ',
  62. 1,
  63. None,
  64. '___sec18'),
  65. (' Example of Classes for Geometric Objects ',
  66. 2,
  67. None,
  68. '___sec19'),
  69. (' Simple Geometric Objects ', 3, None, '___sec20'),
  70. (' Class Curve ', 3, None, '___sec21'),
  71. (' Compound Geometric Objects ', 3, None, '___sec22'),
  72. (' Adding Functionality via Recursion ', 2, None, '___sec23'),
  73. (' Basic Principles of Recursion ', 3, None, '___sec24'),
  74. (' Explaining Recursion ', 3, None, '___sec25'),
  75. (' Scaling, Translating, and Rotating a Figure ',
  76. 2,
  77. 'sketcher:scaling',
  78. 'sketcher:scaling'),
  79. (' Scaling ', 3, None, '___sec27'),
  80. (' Translation ', 3, None, '___sec28'),
  81. (' Rotation ', 3, None, '___sec29')]}
  82. end of tocinfo -->
  83. <body>
  84. <script type="text/x-mathjax-config">
  85. MathJax.Hub.Config({
  86. TeX: {
  87. equationNumbers: { autoNumber: "none" },
  88. extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
  89. }
  90. });
  91. </script>
  92. <script type="text/javascript"
  93. src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
  94. </script>
  95. <a name="part0002"></a>
  96. <p>
  97. <!-- begin top navigation -->
  98. <table style="width: 100%"><tr><td>
  99. <div style="text-align: left;"><a href="._pysketcher001.html"><img src="http://hplgit.github.io/doconce/bundled/html_images/prev1.png" border=0 alt="&laquo; Previous"></a></div>
  100. </td><td>
  101. <div style="text-align: right;"><a href="._pysketcher003.html"><img src="http://hplgit.github.io/doconce/bundled/html_images/next1.png" border=0 alt="Next &raquo;"></a></div>
  102. </td></tr></table>
  103. <!-- end top navigation -->
  104. </p>
  105. <p>
  106. <!-- !split -->
  107. <h1 id="___sec8">Basic Shapes </h1>
  108. <p>
  109. This section presents many of the basic shapes in Pysketcher:
  110. <code>Axis</code>, <code>Distance_wText</code>, <code>Rectangle</code>, <code>Triangle</code>, <code>Arc</code>,
  111. <code>Spring</code>, <code>Dashpot</code>, and <code>Wavy</code>.
  112. Each shape is demonstrated with a figure and a
  113. unit test that shows how the figure is constructed in Python code.
  114. <h2 id="___sec9">Axis </h2>
  115. <p>
  116. The <code>Axis</code> object gives the possibility draw a single axis to
  117. notify a coordinate system. Here is an example where we
  118. draw \( x \) and \( y \) axis of three coordinate systems of different
  119. rotation:
  120. <p>
  121. <br />
  122. <br />
  123. <p>
  124. <center><p><img src="fig-tut/Axis.png" align="bottom" width=500></p></center>
  125. <p>
  126. <br />
  127. <br />
  128. <p>
  129. The corresponding code looks like this:
  130. <p>
  131. <!-- code=python (!bc pycod) typeset with pygments style "default" -->
  132. <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>():
  133. drawing_tool<span style="color: #666666">.</span>set_coordinate_system(
  134. 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>,
  135. instruction_file<span style="color: #666666">=</span><span style="color: #BA2121">&#39;tmp_Axis.py&#39;</span>)
  136. <span style="color: #408080; font-style: italic"># Draw normal x and y axis with origin at (7.5, 2)</span>
  137. <span style="color: #408080; font-style: italic"># in the coordinate system of the sketch: [0,15]x[-7,8]</span>
  138. 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>)
  139. 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>)
  140. 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})
  141. system<span style="color: #666666">.</span>draw()
  142. drawing_tool<span style="color: #666666">.</span>display()
  143. <span style="color: #408080; font-style: italic"># Rotate this system 40 degrees counter clockwise</span>
  144. <span style="color: #408080; font-style: italic"># and draw it with dashed lines</span>
  145. system<span style="color: #666666">.</span>set_linestyle(<span style="color: #BA2121">&#39;dashed&#39;</span>)
  146. 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>))
  147. system<span style="color: #666666">.</span>draw()
  148. drawing_tool<span style="color: #666666">.</span>display()
  149. <span style="color: #408080; font-style: italic"># Rotate this system another 220 degrees and show</span>
  150. <span style="color: #408080; font-style: italic"># with dotted lines</span>
  151. system<span style="color: #666666">.</span>set_linestyle(<span style="color: #BA2121">&#39;dotted&#39;</span>)
  152. 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>))
  153. system<span style="color: #666666">.</span>draw()
  154. drawing_tool<span style="color: #666666">.</span>display()
  155. drawing_tool<span style="color: #666666">.</span>display(<span style="color: #BA2121">&#39;Axis&#39;</span>)
  156. </pre></div>
  157. <h2 id="___sec10">Distance with Text </h2>
  158. <p>
  159. The object <code>Distance_wText</code> is used to display an arrow, to indicate
  160. a distance in a sketch, with an additional text in the middle of the arrow.
  161. <p>
  162. The figure
  163. <p>
  164. <br />
  165. <br />
  166. <p>
  167. <center><p><img src="fig-tut/Distance_wText.png" align="bottom" width=500></p></center>
  168. <p>
  169. <br />
  170. <br />
  171. <p>
  172. was produced by this code:
  173. <p>
  174. <!-- code=python (!bc pycod) typeset with pygments style "default" -->
  175. <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>():
  176. drawing_tool<span style="color: #666666">.</span>set_coordinate_system(
  177. 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>,
  178. 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>)
  179. fontsize<span style="color: #666666">=14</span>
  180. 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>
  181. examples <span style="color: #666666">=</span> Composition({
  182. <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),
  183. <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),
  184. <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),
  185. <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),
  186. <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),
  187. <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,
  188. text_spacing<span style="color: #666666">=-1./60</span>),
  189. <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,
  190. text_spacing<span style="color: #666666">=-1./40</span>, alignment<span style="color: #666666">=</span><span style="color: #BA2121">&#39;right&#39;</span>),
  191. <span style="color: #BA2121">&#39;c1&#39;</span>: Text_wArrow(<span style="color: #BA2121">&#39;text_spacing=-1./60&#39;</span>,
  192. (<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>),
  193. fontsize<span style="color: #666666">=10</span>, alignment<span style="color: #666666">=</span><span style="color: #BA2121">&#39;left&#39;</span>),
  194. <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>,
  195. (<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>),
  196. fontsize<span style="color: #666666">=10</span>, alignment<span style="color: #666666">=</span><span style="color: #BA2121">&#39;left&#39;</span>),
  197. })
  198. examples<span style="color: #666666">.</span>draw()
  199. drawing_tool<span style="color: #666666">.</span>display(<span style="color: #BA2121">&#39;Distance_wText and text positioning&#39;</span>)
  200. </pre></div>
  201. <p>
  202. Note the use of <code>Text_wArrow</code> to write an explaining text with an
  203. associated arrow, here used to explain how
  204. the <code>text_spacing</code> and <code>alignment</code> arguments can be used to adjust
  205. the appearance of the text that goes with the distance arrow.
  206. <h2 id="___sec11">Rectangle </h2>
  207. <p>
  208. <center><p><img src="fig-tut/Rectangle.png" align="bottom" width=500></p></center>
  209. <p>
  210. <br />
  211. <br />
  212. <p>
  213. The above figure can be produced by the following code.
  214. <p>
  215. <!-- code=python (!bc pycod) typeset with pygments style "default" -->
  216. <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>():
  217. L <span style="color: #666666">=</span> <span style="color: #666666">3.0</span>
  218. W <span style="color: #666666">=</span> <span style="color: #666666">4.0</span>
  219. drawing_tool<span style="color: #666666">.</span>set_coordinate_system(
  220. 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,
  221. 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>)
  222. drawing_tool<span style="color: #666666">.</span>set_linecolor(<span style="color: #BA2121">&#39;blue&#39;</span>)
  223. drawing_tool<span style="color: #666666">.</span>set_grid(<span style="color: #008000">True</span>)
  224. xpos <span style="color: #666666">=</span> W<span style="color: #666666">/2</span>
  225. 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)
  226. r<span style="color: #666666">.</span>draw()
  227. r<span style="color: #666666">.</span>draw_dimensions()
  228. drawing_tool<span style="color: #666666">.</span>display(<span style="color: #BA2121">&#39;Rectangle&#39;</span>)
  229. </pre></div>
  230. <p>
  231. The <code>draw_dimension</code> method adds explanation of dimensions and various
  232. important argument in the construction of a shape.
  233. <h2 id="___sec12">Triangle </h2>
  234. <p>
  235. <center><p><img src="fig-tut/Triangle.png" align="bottom" width=500></p></center>
  236. <p>
  237. <br />
  238. <br />
  239. <p>
  240. The code below produces the figure.
  241. <p>
  242. <!-- code=python (!bc pycod) typeset with pygments style "default" -->
  243. <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>():
  244. L <span style="color: #666666">=</span> <span style="color: #666666">3.0</span>
  245. W <span style="color: #666666">=</span> <span style="color: #666666">4.0</span>
  246. drawing_tool<span style="color: #666666">.</span>set_coordinate_system(
  247. 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,
  248. 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>)
  249. drawing_tool<span style="color: #666666">.</span>set_linecolor(<span style="color: #BA2121">&#39;blue&#39;</span>)
  250. drawing_tool<span style="color: #666666">.</span>set_grid(<span style="color: #008000">True</span>)
  251. xpos <span style="color: #666666">=</span> <span style="color: #666666">1</span>
  252. 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))
  253. t<span style="color: #666666">.</span>draw()
  254. t<span style="color: #666666">.</span>draw_dimensions()
  255. drawing_tool<span style="color: #666666">.</span>display(<span style="color: #BA2121">&#39;Triangle&#39;</span>)
  256. </pre></div>
  257. <p>
  258. Here, the <code>draw_dimension</code> method writes the name of the corners at the
  259. position of the corners, which does not always look nice (the present figure
  260. is an example). For a high-quality sketch one would add some spacing
  261. to the location of the p1, p2, and even p3 texts.
  262. <h2 id="___sec13">Arc </h2>
  263. <p>
  264. <center><p><img src="fig-tut/Arc.png" align="bottom" width=400></p></center>
  265. <p>
  266. <br />
  267. <br />
  268. <p>
  269. An arc like the one above is produced by
  270. <p>
  271. <!-- code=python (!bc pycod) typeset with pygments style "default" -->
  272. <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>():
  273. L <span style="color: #666666">=</span> <span style="color: #666666">4.0</span>
  274. W <span style="color: #666666">=</span> <span style="color: #666666">4.0</span>
  275. drawing_tool<span style="color: #666666">.</span>set_coordinate_system(
  276. 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,
  277. 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>)
  278. drawing_tool<span style="color: #666666">.</span>set_linecolor(<span style="color: #BA2121">&#39;blue&#39;</span>)
  279. drawing_tool<span style="color: #666666">.</span>set_grid(<span style="color: #008000">True</span>)
  280. center <span style="color: #666666">=</span> point(<span style="color: #666666">0</span>,<span style="color: #666666">0</span>)
  281. radius <span style="color: #666666">=</span> L<span style="color: #666666">/2</span>
  282. start_angle <span style="color: #666666">=</span> <span style="color: #666666">60</span>
  283. arc_angle <span style="color: #666666">=</span> <span style="color: #666666">45</span>
  284. a <span style="color: #666666">=</span> Arc(center, radius, start_angle, arc_angle)
  285. a<span style="color: #666666">.</span>set_arrow(<span style="color: #BA2121">&#39;-&gt;&#39;</span>)
  286. a<span style="color: #666666">.</span>draw()
  287. R1 <span style="color: #666666">=</span> <span style="color: #666666">1.25*</span>radius
  288. R2 <span style="color: #666666">=</span> <span style="color: #666666">1.5*</span>radius
  289. R <span style="color: #666666">=</span> <span style="color: #666666">2*</span>radius
  290. a<span style="color: #666666">.</span>dimensions <span style="color: #666666">=</span> {
  291. <span style="color: #BA2121">&#39;start_angle&#39;</span>: Arc_wText(
  292. <span style="color: #BA2121">&#39;start_angle&#39;</span>, center, R1, start_angle<span style="color: #666666">=0</span>,
  293. arc_angle<span style="color: #666666">=</span>start_angle, text_spacing<span style="color: #666666">=1/10.</span>),
  294. <span style="color: #BA2121">&#39;arc_angle&#39;</span>: Arc_wText(
  295. <span style="color: #BA2121">&#39;arc_angle&#39;</span>, center, R2, start_angle<span style="color: #666666">=</span>start_angle,
  296. arc_angle<span style="color: #666666">=</span>arc_angle, text_spacing<span style="color: #666666">=1/20.</span>),
  297. <span style="color: #BA2121">&#39;r=0&#39;</span>: Line(center, center <span style="color: #666666">+</span>
  298. point(R<span style="color: #666666">*</span>cos(radians(start_angle)),
  299. R<span style="color: #666666">*</span>sin(radians(start_angle)))),
  300. <span style="color: #BA2121">&#39;r=start_angle&#39;</span>: Line(center, center <span style="color: #666666">+</span>
  301. point(R<span style="color: #666666">*</span>cos(radians(start_angle<span style="color: #666666">+</span>arc_angle)),
  302. R<span style="color: #666666">*</span>sin(radians(start_angle<span style="color: #666666">+</span>arc_angle)))),
  303. <span style="color: #BA2121">&#39;r=start+arc_angle&#39;</span>: Line(center, center <span style="color: #666666">+</span>
  304. point(R, <span style="color: #666666">0</span>))<span style="color: #666666">.</span>set_linestyle(<span style="color: #BA2121">&#39;dashed&#39;</span>),
  305. <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>),
  306. <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>)),
  307. }
  308. <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:
  309. dim <span style="color: #666666">=</span> a<span style="color: #666666">.</span>dimensions[dimension]
  310. dim<span style="color: #666666">.</span>set_linestyle(<span style="color: #BA2121">&#39;dashed&#39;</span>)
  311. dim<span style="color: #666666">.</span>set_linewidth(<span style="color: #666666">1</span>)
  312. dim<span style="color: #666666">.</span>set_linecolor(<span style="color: #BA2121">&#39;black&#39;</span>)
  313. a<span style="color: #666666">.</span>draw_dimensions()
  314. drawing_tool<span style="color: #666666">.</span>display(<span style="color: #BA2121">&#39;Arc&#39;</span>)
  315. </pre></div>
  316. <h2 id="___sec14">Spring </h2>
  317. <p>
  318. <center><p><img src="fig-tut/Spring.png" align="bottom" width=800></p></center>
  319. <p>
  320. <br />
  321. <br />
  322. <p>
  323. The code for making this spring is
  324. <p>
  325. <!-- code=python (!bc pycod) typeset with pygments style "default" -->
  326. <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>():
  327. L <span style="color: #666666">=</span> <span style="color: #666666">5.0</span>
  328. W <span style="color: #666666">=</span> <span style="color: #666666">2.0</span>
  329. drawing_tool<span style="color: #666666">.</span>set_coordinate_system(
  330. 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,
  331. 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>)
  332. drawing_tool<span style="color: #666666">.</span>set_linecolor(<span style="color: #BA2121">&#39;blue&#39;</span>)
  333. drawing_tool<span style="color: #666666">.</span>set_grid(<span style="color: #008000">True</span>)
  334. xpos <span style="color: #666666">=</span> W
  335. 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>)
  336. s1_title <span style="color: #666666">=</span> Text(<span style="color: #BA2121">&#39;Default Spring&#39;</span>,
  337. 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>))
  338. s1<span style="color: #666666">.</span>draw()
  339. s1_title<span style="color: #666666">.</span>draw()
  340. <span style="color: #408080; font-style: italic">#s1.draw_dimensions()</span>
  341. xpos <span style="color: #666666">+=</span> <span style="color: #666666">3*</span>W
  342. 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>,
  343. 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>)
  344. s2<span style="color: #666666">.</span>draw()
  345. s2<span style="color: #666666">.</span>draw_dimensions()
  346. drawing_tool<span style="color: #666666">.</span>display(<span style="color: #BA2121">&#39;Spring&#39;</span>)
  347. </pre></div>
  348. <h2 id="___sec15">Dashpot </h2>
  349. <p>
  350. <center><p><img src="fig-tut/Dashpot.png" align="bottom" width=600></p></center>
  351. <p>
  352. <br />
  353. <br />
  354. <p>
  355. This dashpot is produced by
  356. <p>
  357. <!-- code=python (!bc pycod) typeset with pygments style "default" -->
  358. <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>():
  359. L <span style="color: #666666">=</span> <span style="color: #666666">5.0</span>
  360. W <span style="color: #666666">=</span> <span style="color: #666666">2.0</span>
  361. xpos <span style="color: #666666">=</span> <span style="color: #666666">0</span>
  362. drawing_tool<span style="color: #666666">.</span>set_coordinate_system(
  363. 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,
  364. 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>)
  365. drawing_tool<span style="color: #666666">.</span>set_linecolor(<span style="color: #BA2121">&#39;blue&#39;</span>)
  366. drawing_tool<span style="color: #666666">.</span>set_grid(<span style="color: #008000">True</span>)
  367. <span style="color: #408080; font-style: italic"># Default (simple) dashpot</span>
  368. xpos <span style="color: #666666">=</span> <span style="color: #666666">1.5</span>
  369. 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)
  370. d1_title <span style="color: #666666">=</span> Text(<span style="color: #BA2121">&#39;Dashpot (default)&#39;</span>,
  371. 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>))
  372. d1<span style="color: #666666">.</span>draw()
  373. d1_title<span style="color: #666666">.</span>draw()
  374. <span style="color: #408080; font-style: italic"># Dashpot for animation with fixed bar_length, dashpot_length and</span>
  375. <span style="color: #408080; font-style: italic"># prescribed piston_pos</span>
  376. xpos <span style="color: #666666">+=</span> <span style="color: #666666">2.5*</span>W
  377. 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>,
  378. 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)
  379. d2<span style="color: #666666">.</span>draw()
  380. d2<span style="color: #666666">.</span>draw_dimensions()
  381. drawing_tool<span style="color: #666666">.</span>display(<span style="color: #BA2121">&#39;Dashpot&#39;</span>)
  382. </pre></div>
  383. <h2 id="___sec16">Wavy </h2>
  384. <p>
  385. Looks strange. Fix x axis.
  386. <h2 id="___sec17">Stochastic curves </h2>
  387. <p>
  388. The <code>StochasticWavyCurve</code> object offers three precomputed
  389. graphics that have a random variation:
  390. <p>
  391. <br />
  392. <br />
  393. <p>
  394. <center><p><img src="fig-tut/StochasticWavyCurve.png" align="bottom" width=600></p></center>
  395. <p>
  396. <br />
  397. <br />
  398. <p>
  399. The usage is simple. The construction
  400. <p>
  401. <!-- code=python (!bc pycod) typeset with pygments style "default" -->
  402. <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>)
  403. </pre></div>
  404. <p>
  405. picks the second curve (the three are numbered 0, 1, and 2),
  406. and the first 40% of that curve. In case one desires another extent
  407. of the axis, one can just scale the coordinates directly as these
  408. are stored in the arrays <code>curve.x[curve_no]</code> and
  409. <code>curve.y[curve_no]</code>.
  410. <p>
  411. <p>
  412. <!-- begin bottom navigation -->
  413. <table style="width: 100%"><tr><td>
  414. <div style="text-align: left;"><a href="._pysketcher001.html"><img src="http://hplgit.github.io/doconce/bundled/html_images/prev1.png" border=0 alt="&laquo; Previous"></a></div>
  415. </td><td>
  416. <div style="text-align: right;"><a href="._pysketcher003.html"><img src="http://hplgit.github.io/doconce/bundled/html_images/next1.png" border=0 alt="Next &raquo;"></a></div>
  417. </td></tr></table>
  418. <!-- end bottom navigation -->
  419. </p>
  420. <!-- ------------------- end of main content --------------- -->
  421. </body>
  422. </html>