pysketcher.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. <!-- Bootstrap style: bootswatch_readable -->
  13. <link href="http://netdna.bootstrapcdn.com/bootswatch/3.1.1/readable/bootstrap.min.css" rel="stylesheet">
  14. <!-- not necessary
  15. <link href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
  16. -->
  17. <style type="text/css">
  18. /* Add scrollbar to dropdown menus in bootstrap navigation bar */
  19. .dropdown-menu {
  20. height: auto;
  21. max-height: 400px;
  22. overflow-x: hidden;
  23. }
  24. </style>
  25. </head>
  26. <!-- tocinfo
  27. {'highest level': 1,
  28. 'sections': [('A first glimpse of Pysketcher', 1, None, '___sec0'),
  29. ('Basic construction of sketches', 2, None, '___sec1'),
  30. ('Basic drawing', 3, None, '___sec2'),
  31. ('Groups of objects', 3, None, '___sec3'),
  32. ('Changing line styles and colors', 3, None, '___sec4'),
  33. ('The figure composition as an object hierarchy',
  34. 3,
  35. None,
  36. '___sec5'),
  37. ('Animation: translating the vehicle', 3, None, '___sec6'),
  38. ('Animation: rolling the wheels',
  39. 3,
  40. 'sketcher:vehicle1:anim',
  41. 'sketcher:vehicle1:anim'),
  42. ('Basic shapes', 1, None, '___sec8'),
  43. ('Axis', 2, None, '___sec9'),
  44. ('Distance with text', 2, None, '___sec10'),
  45. ('Rectangle', 2, None, '___sec11'),
  46. ('Triangle', 2, None, '___sec12'),
  47. ('Arc', 2, None, '___sec13'),
  48. ('Spring', 2, None, '___sec14'),
  49. ('Dashpot', 2, None, '___sec15'),
  50. ('Wavy', 2, None, '___sec16'),
  51. ('Stochastic curves', 2, None, '___sec17'),
  52. ('Inner workings of the Pysketcher tool', 1, None, '___sec18'),
  53. ('Example of classes for geometric objects',
  54. 2,
  55. None,
  56. '___sec19'),
  57. ('Simple geometric objects', 3, None, '___sec20'),
  58. ('Class curve', 3, None, '___sec21'),
  59. ('Compound geometric objects', 3, None, '___sec22'),
  60. ('Adding functionality via recursion', 2, None, '___sec23'),
  61. ('Basic principles of recursion', 3, None, '___sec24'),
  62. ('Explaining recursion', 3, None, '___sec25'),
  63. ('Scaling, translating, and rotating a figure',
  64. 2,
  65. 'sketcher:scaling',
  66. 'sketcher:scaling'),
  67. ('Scaling', 3, None, '___sec27'),
  68. ('Translation', 3, None, '___sec28'),
  69. ('Rotation', 3, None, '___sec29')]}
  70. end of tocinfo -->
  71. <body>
  72. <script type="text/x-mathjax-config">
  73. MathJax.Hub.Config({
  74. TeX: {
  75. equationNumbers: { autoNumber: "none" },
  76. extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
  77. }
  78. });
  79. </script>
  80. <script type="text/javascript"
  81. src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
  82. </script>
  83. <!-- Bootstrap navigation bar -->
  84. <div class="navbar navbar-default navbar-fixed-top">
  85. <div class="navbar-header">
  86. <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
  87. <span class="icon-bar"></span>
  88. <span class="icon-bar"></span>
  89. <span class="icon-bar"></span>
  90. </button>
  91. <a class="navbar-brand" href="pysketcher.html">Using Pysketcher to Create Principal Sketches of Physics Problems</a>
  92. </div>
  93. <div class="navbar-collapse collapse navbar-responsive-collapse">
  94. <ul class="nav navbar-nav navbar-right">
  95. <li class="dropdown">
  96. <a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
  97. <ul class="dropdown-menu">
  98. <!-- navigation toc: --> <li><a href="._pysketcher001.html#___sec0" style="font-size: 80%;"><b>A first glimpse of Pysketcher</b></a></li>
  99. <!-- navigation toc: --> <li><a href="._pysketcher001.html#___sec1" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Basic construction of sketches</a></li>
  100. <!-- navigation toc: --> <li><a href="._pysketcher001.html#___sec2" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Basic drawing</a></li>
  101. <!-- navigation toc: --> <li><a href="._pysketcher001.html#___sec3" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Groups of objects</a></li>
  102. <!-- navigation toc: --> <li><a href="._pysketcher001.html#___sec4" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Changing line styles and colors</a></li>
  103. <!-- navigation toc: --> <li><a href="._pysketcher001.html#___sec5" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The figure composition as an object hierarchy</a></li>
  104. <!-- navigation toc: --> <li><a href="._pysketcher001.html#___sec6" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Animation: translating the vehicle</a></li>
  105. <!-- navigation toc: --> <li><a href="._pysketcher001.html#sketcher:vehicle1:anim" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Animation: rolling the wheels</a></li>
  106. <!-- navigation toc: --> <li><a href="._pysketcher002.html#___sec8" style="font-size: 80%;"><b>Basic shapes</b></a></li>
  107. <!-- navigation toc: --> <li><a href="._pysketcher002.html#___sec9" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Axis</a></li>
  108. <!-- navigation toc: --> <li><a href="._pysketcher002.html#___sec10" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Distance with text</a></li>
  109. <!-- navigation toc: --> <li><a href="._pysketcher002.html#___sec11" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Rectangle</a></li>
  110. <!-- navigation toc: --> <li><a href="._pysketcher002.html#___sec12" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Triangle</a></li>
  111. <!-- navigation toc: --> <li><a href="._pysketcher002.html#___sec13" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Arc</a></li>
  112. <!-- navigation toc: --> <li><a href="._pysketcher002.html#___sec14" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Spring</a></li>
  113. <!-- navigation toc: --> <li><a href="._pysketcher002.html#___sec15" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Dashpot</a></li>
  114. <!-- navigation toc: --> <li><a href="._pysketcher002.html#___sec16" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Wavy</a></li>
  115. <!-- navigation toc: --> <li><a href="._pysketcher002.html#___sec17" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Stochastic curves</a></li>
  116. <!-- navigation toc: --> <li><a href="._pysketcher003.html#___sec18" style="font-size: 80%;"><b>Inner workings of the Pysketcher tool</b></a></li>
  117. <!-- navigation toc: --> <li><a href="._pysketcher003.html#___sec19" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Example of classes for geometric objects</a></li>
  118. <!-- navigation toc: --> <li><a href="._pysketcher003.html#___sec20" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Simple geometric objects</a></li>
  119. <!-- navigation toc: --> <li><a href="._pysketcher003.html#___sec21" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Class curve</a></li>
  120. <!-- navigation toc: --> <li><a href="._pysketcher003.html#___sec22" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Compound geometric objects</a></li>
  121. <!-- navigation toc: --> <li><a href="._pysketcher003.html#___sec23" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Adding functionality via recursion</a></li>
  122. <!-- navigation toc: --> <li><a href="._pysketcher003.html#___sec24" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Basic principles of recursion</a></li>
  123. <!-- navigation toc: --> <li><a href="._pysketcher003.html#___sec25" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Explaining recursion</a></li>
  124. <!-- navigation toc: --> <li><a href="._pysketcher003.html#sketcher:scaling" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Scaling, translating, and rotating a figure</a></li>
  125. <!-- navigation toc: --> <li><a href="._pysketcher003.html#___sec27" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Scaling</a></li>
  126. <!-- navigation toc: --> <li><a href="._pysketcher003.html#___sec28" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Translation</a></li>
  127. <!-- navigation toc: --> <li><a href="._pysketcher003.html#___sec29" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Rotation</a></li>
  128. </ul>
  129. </li>
  130. </ul>
  131. </div>
  132. </div>
  133. </div> <!-- end of navigation bar -->
  134. <div class="container">
  135. <p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
  136. <a name="part0000"></a>
  137. <!-- ------------------- main content ---------------------- -->
  138. <div class="jumbotron">
  139. <center><h1>Using Pysketcher to Create Principal Sketches of Physics Problems</h1></center> <!-- document title -->
  140. <p>
  141. <!-- author(s): Hans Petter Langtangen -->
  142. <center>
  143. <b>Hans Petter Langtangen</b> [1, 2]
  144. </center>
  145. <p>
  146. <!-- institution(s) -->
  147. <center>[1] <b>Center for Biomedical Computing, Simula Research Laboratory</b></center>
  148. <center>[2] <b>Department of Informatics, University of Oslo</b></center>
  149. <br>
  150. <p>
  151. <center><h4>Dec 22, 2015</h4></center> <!-- date -->
  152. <br>
  153. <p>
  154. <!-- begin box -->
  155. <div style="width: 95%; padding: 10px; border: 1px solid #000; border-radius: 4px;">
  156. This document is derived from Chapter 9 in the book
  157. <a href="http://www.amazon.com/Scientific-Programming-Computational-Science-Engineering/dp/3642549586/ref=sr_1_2?s=books&ie=UTF8&qid=1407225588&sr=1-2&keywords=langtangen" target="_self">A Primer on Scientific Programming with Python</a>, by H. P. Langtangen,
  158. 4th edition, Springer, 2014.
  159. </div>
  160. <!-- end box -->
  161. <p>
  162. <b>Abstract.</b> Pysketcher is a Python package which allows principal sketches of
  163. physics and mechanics problems to be realized through short programs
  164. instead of interactive (and potentially tedious and inaccurate)
  165. drawing. Elements of the sketch, such as lines, circles, angles,
  166. forces, coordinate systems, etc., are realized as objects and
  167. collected in hierarchical structures. Parts of the hierarchical
  168. structures can easily change line styles and colors, or be copied,
  169. scaled, translated, and rotated. These features make it
  170. straightforward to move parts of the sketch to create animation,
  171. usually in accordance with the physics of the underlying problem.
  172. Exact dimensioning of the elements in the sketch is trivial to obtain
  173. since distances are specified in computer code.
  174. <p>
  175. Pysketcher is easy to learn from a number of examples. Beyond
  176. essential Python programming and a knowledge about mechanics problems,
  177. no further background is required.
  178. <p>
  179. <!-- Task (can be questions): make sketches of physical problems, see fig -->
  180. <!-- through user-friendly composition of basic shapes -->
  181. <!-- Desired knowledge: plotting curves, basic OO (ch. X.Y, ...) -->
  182. <!-- Required knowledge? -->
  183. <!-- Learning Goals: these targets the inner workings of pysketcher, -->
  184. <!-- which is just a part of this document... -->
  185. <p>
  186. <p><a href="._pysketcher001.html" class="btn btn-primary btn-lg">Read &raquo;</a></p>
  187. </div> <!-- end jumbotron -->
  188. <p>
  189. <!-- navigation buttons at the bottom of the page -->
  190. <ul class="pagination">
  191. <li class="active"><a href="._pysketcher000.html">1</a></li>
  192. <li><a href="._pysketcher001.html">2</a></li>
  193. <li><a href="._pysketcher002.html">3</a></li>
  194. <li><a href="._pysketcher003.html">4</a></li>
  195. <li><a href="._pysketcher001.html">&raquo;</a></li>
  196. </ul>
  197. <!-- ------------------- end of main content --------------- -->
  198. </div> <!-- end container -->
  199. <!-- include javascript, jQuery *first* -->
  200. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  201. <script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
  202. <!-- Bootstrap footer
  203. <footer>
  204. <a href="http://..."><img width="250" align=right src="http://..."></a>
  205. </footer>
  206. -->
  207. </body>
  208. </html>