index.html 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. <!doctype html>
  2. <html lang="en" class="no-js">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width,initial-scale=1">
  6. <link rel="shortcut icon" href="../assets/images/favicon.png">
  7. <meta name="generator" content="mkdocs-1.1.2, mkdocs-material-5.5.3">
  8. <title>Learning by Example - Jypyter Sketcher</title>
  9. <link rel="stylesheet" href="../assets/stylesheets/main.947af8d5.min.css">
  10. <link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
  11. <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700%7CRoboto+Mono&display=fallback">
  12. <style>body,input{font-family:"Roboto",-apple-system,BlinkMacSystemFont,Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"Roboto Mono",SFMono-Regular,Consolas,Menlo,monospace}</style>
  13. </head>
  14. <body dir="ltr">
  15. <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
  16. <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
  17. <label class="md-overlay" for="__drawer"></label>
  18. <div data-md-component="skip">
  19. <a href="#a-language-to-describe-a-sketch" class="md-skip">
  20. Skip to content
  21. </a>
  22. </div>
  23. <div data-md-component="announce">
  24. </div>
  25. <header class="md-header" data-md-component="header">
  26. <nav class="md-header-nav md-grid" aria-label="Header">
  27. <a href=".." title="Jypyter Sketcher" class="md-header-nav__button md-logo" aria-label="Jypyter Sketcher">
  28. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 003-3 3 3 0 00-3-3 3 3 0 00-3 3 3 3 0 003 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54z"/></svg>
  29. </a>
  30. <label class="md-header-nav__button md-icon" for="__drawer">
  31. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2z"/></svg>
  32. </label>
  33. <div class="md-header-nav__title" data-md-component="header-title">
  34. <div class="md-header-nav__ellipsis">
  35. <span class="md-header-nav__topic md-ellipsis">
  36. Jypyter Sketcher
  37. </span>
  38. <span class="md-header-nav__topic md-ellipsis">
  39. Learning by Example
  40. </span>
  41. </div>
  42. </div>
  43. <label class="md-header-nav__button md-icon" for="__search">
  44. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0116 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 019.5 16 6.5 6.5 0 013 9.5 6.5 6.5 0 019.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/></svg>
  45. </label>
  46. <div class="md-search" data-md-component="search" role="dialog">
  47. <label class="md-search__overlay" for="__search"></label>
  48. <div class="md-search__inner" role="search">
  49. <form class="md-search__form" name="search">
  50. <input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" data-md-state="active">
  51. <label class="md-search__icon md-icon" for="__search">
  52. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0116 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 019.5 16 6.5 6.5 0 013 9.5 6.5 6.5 0 019.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/></svg>
  53. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
  54. </label>
  55. <button type="reset" class="md-search__icon md-icon" aria-label="Clear" data-md-component="search-reset" tabindex="-1">
  56. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/></svg>
  57. </button>
  58. </form>
  59. <div class="md-search__output">
  60. <div class="md-search__scrollwrap" data-md-scrollfix>
  61. <div class="md-search-result" data-md-component="search-result">
  62. <div class="md-search-result__meta">
  63. Initializing search
  64. </div>
  65. <ol class="md-search-result__list"></ol>
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. </div>
  71. </nav>
  72. </header>
  73. <div class="md-container" data-md-component="container">
  74. <main class="md-main" data-md-component="main">
  75. <div class="md-main__inner md-grid">
  76. <div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
  77. <div class="md-sidebar__scrollwrap">
  78. <div class="md-sidebar__inner">
  79. <nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
  80. <label class="md-nav__title" for="__drawer">
  81. <a href=".." title="Jypyter Sketcher" class="md-nav__button md-logo" aria-label="Jypyter Sketcher">
  82. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 003-3 3 3 0 00-3-3 3 3 0 00-3 3 3 3 0 003 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54z"/></svg>
  83. </a>
  84. Jypyter Sketcher
  85. </label>
  86. <ul class="md-nav__list" data-md-scrollfix>
  87. <li class="md-nav__item">
  88. <a href=".." title="Home" class="md-nav__link">
  89. Home
  90. </a>
  91. </li>
  92. <li class="md-nav__item">
  93. <a href="../about/" title="About" class="md-nav__link">
  94. About
  95. </a>
  96. </li>
  97. <li class="md-nav__item">
  98. <a href="../presentation/" title="Presentation" class="md-nav__link">
  99. Presentation
  100. </a>
  101. </li>
  102. <li class="md-nav__item md-nav__item--active">
  103. <input class="md-nav__toggle md-toggle" data-md-toggle="toc" type="checkbox" id="__toc">
  104. <label class="md-nav__link md-nav__link--active" for="__toc">
  105. Learning by Example
  106. <span class="md-nav__icon md-icon">
  107. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 9h14V7H3v2m0 4h14v-2H3v2m0 4h14v-2H3v2m16 0h2v-2h-2v2m0-10v2h2V7h-2m0 6h2v-2h-2v2z"/></svg>
  108. </span>
  109. </label>
  110. <a href="./" title="Learning by Example" class="md-nav__link md-nav__link--active">
  111. Learning by Example
  112. </a>
  113. <nav class="md-nav md-nav--secondary" aria-label="Table of contents">
  114. <label class="md-nav__title" for="__toc">
  115. <span class="md-nav__icon md-icon">
  116. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
  117. </span>
  118. Table of contents
  119. </label>
  120. <ul class="md-nav__list" data-md-scrollfix>
  121. <li class="md-nav__item">
  122. <a href="#a-language-to-describe-a-sketch" class="md-nav__link">
  123. A language to describe a sketch
  124. </a>
  125. </li>
  126. <li class="md-nav__item">
  127. <a href="#example" class="md-nav__link">
  128. Example
  129. </a>
  130. <nav class="md-nav" aria-label="Example">
  131. <ul class="md-nav__list">
  132. <li class="md-nav__item">
  133. <a href="#the-final-sketch" class="md-nav__link">
  134. The final sketch
  135. </a>
  136. </li>
  137. <li class="md-nav__item">
  138. <a href="#support-files" class="md-nav__link">
  139. Support files
  140. </a>
  141. </li>
  142. <li class="md-nav__item">
  143. <a href="#the-yaml-definition" class="md-nav__link">
  144. The yaml definition
  145. </a>
  146. <nav class="md-nav" aria-label="The yaml definition">
  147. <ul class="md-nav__list">
  148. <li class="md-nav__item">
  149. <a href="#libraries" class="md-nav__link">
  150. Libraries
  151. </a>
  152. </li>
  153. <li class="md-nav__item">
  154. <a href="#constants-construction-parameters" class="md-nav__link">
  155. Constants: Construction parameters
  156. </a>
  157. </li>
  158. <li class="md-nav__item">
  159. <a href="#frame-core-geometric-parameters" class="md-nav__link">
  160. Frame: core geometric parameters
  161. </a>
  162. </li>
  163. <li class="md-nav__item">
  164. <a href="#the-body-object" class="md-nav__link">
  165. The body object
  166. </a>
  167. </li>
  168. <li class="md-nav__item">
  169. <a href="#the-plan-object" class="md-nav__link">
  170. The plan object
  171. </a>
  172. </li>
  173. <li class="md-nav__item">
  174. <a href="#the-friction-sketch" class="md-nav__link">
  175. The friction sketch
  176. </a>
  177. </li>
  178. </ul>
  179. </nav>
  180. </li>
  181. <li class="md-nav__item">
  182. <a href="#using-the-parser" class="md-nav__link">
  183. Using the parser
  184. </a>
  185. </li>
  186. <li class="md-nav__item">
  187. <a href="#friction-sketch-hierarchy" class="md-nav__link">
  188. "friction" sketch hierarchy
  189. </a>
  190. </li>
  191. </ul>
  192. </nav>
  193. </li>
  194. </ul>
  195. </nav>
  196. </li>
  197. <li class="md-nav__item">
  198. <a href="../shapereference/" title="Shapes Reference" class="md-nav__link">
  199. Shapes Reference
  200. </a>
  201. </li>
  202. <li class="md-nav__item">
  203. <a href="../yamlsketcher/" title="YAML files Reference" class="md-nav__link">
  204. YAML files Reference
  205. </a>
  206. </li>
  207. <li class="md-nav__item">
  208. <a href="../gallerydoc/" title="Gallery" class="md-nav__link">
  209. Gallery
  210. </a>
  211. </li>
  212. <li class="md-nav__item">
  213. <a href="../resources/Gallery/" title="Gallery Notebook" class="md-nav__link">
  214. Gallery Notebook
  215. </a>
  216. </li>
  217. </ul>
  218. </nav>
  219. </div>
  220. </div>
  221. </div>
  222. <div class="md-sidebar md-sidebar--secondary" data-md-component="toc">
  223. <div class="md-sidebar__scrollwrap">
  224. <div class="md-sidebar__inner">
  225. <nav class="md-nav md-nav--secondary" aria-label="Table of contents">
  226. <label class="md-nav__title" for="__toc">
  227. <span class="md-nav__icon md-icon">
  228. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
  229. </span>
  230. Table of contents
  231. </label>
  232. <ul class="md-nav__list" data-md-scrollfix>
  233. <li class="md-nav__item">
  234. <a href="#a-language-to-describe-a-sketch" class="md-nav__link">
  235. A language to describe a sketch
  236. </a>
  237. </li>
  238. <li class="md-nav__item">
  239. <a href="#example" class="md-nav__link">
  240. Example
  241. </a>
  242. <nav class="md-nav" aria-label="Example">
  243. <ul class="md-nav__list">
  244. <li class="md-nav__item">
  245. <a href="#the-final-sketch" class="md-nav__link">
  246. The final sketch
  247. </a>
  248. </li>
  249. <li class="md-nav__item">
  250. <a href="#support-files" class="md-nav__link">
  251. Support files
  252. </a>
  253. </li>
  254. <li class="md-nav__item">
  255. <a href="#the-yaml-definition" class="md-nav__link">
  256. The yaml definition
  257. </a>
  258. <nav class="md-nav" aria-label="The yaml definition">
  259. <ul class="md-nav__list">
  260. <li class="md-nav__item">
  261. <a href="#libraries" class="md-nav__link">
  262. Libraries
  263. </a>
  264. </li>
  265. <li class="md-nav__item">
  266. <a href="#constants-construction-parameters" class="md-nav__link">
  267. Constants: Construction parameters
  268. </a>
  269. </li>
  270. <li class="md-nav__item">
  271. <a href="#frame-core-geometric-parameters" class="md-nav__link">
  272. Frame: core geometric parameters
  273. </a>
  274. </li>
  275. <li class="md-nav__item">
  276. <a href="#the-body-object" class="md-nav__link">
  277. The body object
  278. </a>
  279. </li>
  280. <li class="md-nav__item">
  281. <a href="#the-plan-object" class="md-nav__link">
  282. The plan object
  283. </a>
  284. </li>
  285. <li class="md-nav__item">
  286. <a href="#the-friction-sketch" class="md-nav__link">
  287. The friction sketch
  288. </a>
  289. </li>
  290. </ul>
  291. </nav>
  292. </li>
  293. <li class="md-nav__item">
  294. <a href="#using-the-parser" class="md-nav__link">
  295. Using the parser
  296. </a>
  297. </li>
  298. <li class="md-nav__item">
  299. <a href="#friction-sketch-hierarchy" class="md-nav__link">
  300. "friction" sketch hierarchy
  301. </a>
  302. </li>
  303. </ul>
  304. </nav>
  305. </li>
  306. </ul>
  307. </nav>
  308. </div>
  309. </div>
  310. </div>
  311. <div class="md-content">
  312. <article class="md-content__inner md-typeset">
  313. <h1>Learning by Example</h1>
  314. <h2 id="a-language-to-describe-a-sketch">A language to describe a sketch</h2>
  315. <p>Pysketcher initial version <a href="">HPL Pysketcher</a> enable sketch definition in python. HPL is showing the hierachical nature of sketches. This is implemented via the Composition function. One can further grasp this using the graphviz_dot function applied to discover the composition herarchy implemented as a graphviz image <a href="#friction-sketch-hierarchy">see The hierarchy of the "friction" sketch</a> at the end of this page.</p>
  316. <p>Due to the hierarchical nature of sketches, it is quite straightforward to think about using yaml as the syntax for defining a sketch.</p>
  317. <p>Benefits are the following:</p>
  318. <ul>
  319. <li>Leaner sketch writing as only data relevant to the context needs to be defined</li>
  320. <li>A more straightforward reading for the same reason</li>
  321. <li>A more robust sketch definition <ul>
  322. <li>The same set of rules is applied to generate a sketch</li>
  323. <li>No further python idiom is be intermingled as opposed to the case of python defined sketches</li>
  324. <li>Don't make me wrong! Data defined versus program defined there is no winner, it's just a matter of context</li>
  325. </ul>
  326. </li>
  327. </ul>
  328. <h2 id="example">Example</h2>
  329. <p>This example provides the yaml content to define the Dry Friction case</p>
  330. <h3 id="the-final-sketch">The final sketch</h3>
  331. <p><img alt="dryfriction sketch" src="../images/dryfriction.svg" /></p>
  332. <p>An inclined plan (the A-B edge) supports a blue rectangle which is dragged down by gravity. The plan makes an angle <span><span class="MathJax_Preview">\theta</span><script type="math/tex">\theta</script></span> with the ground level. Sketch implementation notebook includes a controller enabling the <span><span class="MathJax_Preview">\theta</span><script type="math/tex">\theta</script></span> angle to change. The whole plan, including the body, can rotate arround point B.</p>
  333. <h3 id="support-files">Support files</h3>
  334. <p>The example we are developing now is based upon the "Dry Friction mockup" notebook</p>
  335. <ul>
  336. <li>the rendered html version of the notbook can be viewed <a href="../resources/DryFriction.html">here</a></li>
  337. <li>the notebook can be download <a href="../resources/DryFriction/">here</a></li>
  338. </ul>
  339. <h3 id="the-yaml-definition">The yaml definition</h3>
  340. <p>Sketcher language is defined as a yaml compliant file or string. The yaml file is a dictionnary of "objects". Objects can be regular python objects or sketcher objects.
  341. A skertcher object is composed as follow:</p>
  342. <ul>
  343. <li><strong>a formula</strong>: it's a leaf object, like Rectangle, Circle, Line etc or a composition</li>
  344. <li><strong>a style list</strong>: line or fill colors, line stroke... declared as a yaml hierarchy</li>
  345. <li><strong>a transformation list</strong>: the defined object can be transformed using sketcher transformation: translation, rotation...</li>
  346. </ul>
  347. <p>As a general rule, a new object suppose all parameters to be defined before they are used to construct it.</p>
  348. <p><strong>For example, you can create a circle if the center and the radius have been defined earlier in the file.</strong></p>
  349. <p>The general layout of a sketcher file is as follow:</p>
  350. <ul>
  351. <li><strong>Libraries, Construction Variables, Frame</strong><ul>
  352. <li>declaration of the libraries used by the objects further declared: at least pysketcher is mandatory</li>
  353. <li>various global variable which encompass the "Construction" variables which define the object main physical dimensions, positions...</li>
  354. <li>some "actions" corresponding to executable python sentences<ul>
  355. <li>One mandatory action is the setting of the drawing frame (drawing_tool.set_coordinate_system): it must be declared before any other pysketcher object is used.</li>
  356. <li>Other use case of action is the setting of global parameters like default line color: (drawing_tool.set_linecolor('black')) for example</li>
  357. </ul>
  358. </li>
  359. <li>this is stored in the head string thereafter</li>
  360. <li>The example uses the following objects<ul>
  361. <li>libraries: setting the libraries used for this sketch</li>
  362. <li>constants: all the sketch dimensionning data</li>
  363. <li>frame: all the shapes or geometric objects which will be used by the other shapes</li>
  364. </ul>
  365. </li>
  366. </ul>
  367. </li>
  368. <li><strong>Sketcher Objects</strong><ul>
  369. <li>Usually starting with the declaration of Pysketcher leaf objects (Geometry object like Line, Circle, Rectangle...)</li>
  370. <li>May be aggregated using the composition object</li>
  371. <li>Composition can be made of composition object (recursive behaviour)</li>
  372. <li>Grouping leafs and composition will be further used to apply transformation latter on (based on the "physics")</li>
  373. <li>The example uese three group of shapes<ul>
  374. <li>The body object</li>
  375. <li>The plan object</li>
  376. <li>The friction main object</li>
  377. </ul>
  378. </li>
  379. <li>The plan includes the body</li>
  380. <li>The friction includes the plan (that will be able to rotate as a group) and the ground (will stay fixed)</li>
  381. </ul>
  382. </li>
  383. </ul>
  384. <h4 id="libraries">Libraries</h4>
  385. <pre><code class="python">libraries = &quot;&quot;&quot;\
  386. name: head
  387. shapes:
  388. libraries: [&quot;from math import tan, radians, sin, cos&quot;,&quot;from pysketcher import *&quot;]
  389. &quot;&quot;&quot;
  390. </code></pre>
  391. <h4 id="constants-construction-parameters">Constants: Construction parameters</h4>
  392. <pre><code class="python">constants = &quot;&quot;&quot;\
  393. name: constants
  394. shapes:
  395. fontsize: 18 # size of the characters
  396. g: 9.81 # constant gravity
  397. theta: 30.0 # inclined plane angle
  398. L: 10.0 # sketch sizing parameter
  399. a: 1.0 #
  400. xmin: 0.0 # sketech min Abscissa
  401. ymin: -3.0 # sketech min Ordinate
  402. rl: 2.0 # rectangle width
  403. rL: 1.0 # rectangle length
  404. &quot;&quot;&quot;
  405. </code></pre>
  406. <h4 id="frame-core-geometric-parameters">Frame: core geometric parameters</h4>
  407. <pre><code class="python">frame = &quot;&quot;&quot;\
  408. name: frame
  409. shapes:
  410. setframe: # sketch setup
  411. action: &quot;drawing_tool.set_coordinate_system(xmin=xmin-L/5, xmax=xmin+1.5*L,ymin=ymin, ymax=ymin+1.5*L,instruction_file='tmp_mpl_friction.py')&quot;
  412. setblackline: # default frame values and actions
  413. action: &quot;drawing_tool.set_linecolor('black')&quot;
  414. B: point(a+L,0) # wall right end
  415. A: point(a,tan(radians(theta))*L) # wall left end
  416. normal_vec: point(sin(radians(theta)),cos(radians(theta))) # Vector normal to wall
  417. tangent_vec: point(cos(radians(theta)),-sin(radians(theta))) # Vector tangent to wall
  418. help_line: Line(A,B) # wall line
  419. x: a + 3*L/10. # contact point Abscissa
  420. y: help_line(x=x) # contact point Ordinate
  421. contact: point(x, y) # contact point: middle of the rectangle bottom edge
  422. c: contact + rL/2*normal_vec
  423. &quot;&quot;&quot;
  424. </code></pre>
  425. <h4 id="the-body-object">The body object</h4>
  426. <pre><code class="python">body = &quot;&quot;&quot;\
  427. name: body
  428. shapes:
  429. rectangle:
  430. formula: Rectangle(contact, rl, rL)
  431. style:
  432. linecolor: blue
  433. filled_curves: blue
  434. transform: [&quot;rotate(-theta, contact)&quot;,
  435. &quot;translate(-rl/2*tangent_vec)&quot;]
  436. N:
  437. formula: Force(contact - rl*normal_vec, contact, r'$N$', text_pos='start')
  438. style:
  439. linecolor: black
  440. wheel:
  441. formula: &quot;Composition({'outer': rectangle})&quot;
  442. style:
  443. shadow: 1
  444. mc:
  445. formula: Text(r'$c$', c)
  446. body:
  447. formula: &quot;Composition({'wheel': wheel, 'N': N, 'mc': mc})&quot;
  448. style:
  449. linecolor: black
  450. &quot;&quot;&quot;
  451. </code></pre>
  452. <h4 id="the-plan-object">The plan object</h4>
  453. <pre><code class="python">plan = &quot;&quot;&quot;\
  454. name: plan
  455. shapes:
  456. mB:
  457. formula: Text(r'$B$',B)
  458. mA:
  459. formula: Text(r'$A$', A)
  460. wall:
  461. formula: Wall(x=[A[0], B[0]], y=[A[1], B[1]], thickness=-0.25,transparent=False)
  462. style:
  463. linecolor: black
  464. x_const:
  465. formula: Line(contact, contact + point(0,4))
  466. style:
  467. linestyle: dotted
  468. transform: rotate(-theta, contact)
  469. x_axis:
  470. formula: &quot;Axis(start=contact+ 2*rl*normal_vec, length=2*rl,label='$x$', rotation_angle=-theta)&quot;
  471. plan:
  472. formula: &quot;Composition({'body': body, 'inclined wall': wall, 'x start': x_const, 'x axis': x_axis, 'mA': mA, 'mB': mB})&quot;
  473. &quot;&quot;&quot;
  474. </code></pre>
  475. <h4 id="the-friction-sketch">The friction sketch</h4>
  476. <pre><code class="python">friction = &quot;&quot;&quot;\
  477. name: friction
  478. shapes:
  479. mg:
  480. formula: Gravity(c, rl, text='$Mg$')
  481. style:
  482. linecolor: black
  483. angle:
  484. formula: &quot;Arc_wText(r'$&lt;bslash&gt;theta$', center=B, radius=3, start_angle=180-theta, arc_angle=theta, fontsize=fontsize)&quot;
  485. style:
  486. linecolor: black
  487. linewidth: 1
  488. ground:
  489. formula: Line((B[0]-L/10., 0), (B[0]-L/2.,0))
  490. stlye:
  491. linecolor: black
  492. linestyle: dashed
  493. linewidth: 1
  494. friction:
  495. formula: &quot;Composition({'plan': plan, 'ground': ground, 'mg': mg, 'angle': angle})&quot;
  496. &quot;&quot;&quot;
  497. </code></pre>
  498. <h3 id="using-the-parser">Using the parser</h3>
  499. <p>To parse the above example, the following code do the job.</p>
  500. <ol>
  501. <li>libraries, constants and frame must be used first as all the other bits needs one or more variable they defines.</li>
  502. <li>After, any other sketch can be parsed, the order just need to respect precedence (if one object uses another it must be parsed after)</li>
  503. <li>this setting allows naturally a modular definition of sketch objects</li>
  504. </ol>
  505. <p>The parser checks for syntax precedence and warns of any detected error.</p>
  506. <pre><code class="python">myfig = {}
  507. if sketchParse(libraries,myfig):
  508. if sketchParse(constants,myfig):
  509. if sketchParse(frame,myfig):
  510. if sketchParse(body,myfig):
  511. if sketchParse(plan,myfig):
  512. if sketchParse(friction,myfig):
  513. print(&quot;success&quot;)
  514. </code></pre>
  515. <h3 id="friction-sketch-hierarchy">"friction" sketch hierarchy</h3>
  516. <p><img alt="" src="../images/dotdryfriction.svg" /></p>
  517. </article>
  518. </div>
  519. </div>
  520. </main>
  521. <footer class="md-footer">
  522. <div class="md-footer-nav">
  523. <nav class="md-footer-nav__inner md-grid" aria-label="Footer">
  524. <a href="../presentation/" title="Presentation" class="md-footer-nav__link md-footer-nav__link--prev" rel="prev">
  525. <div class="md-footer-nav__button md-icon">
  526. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
  527. </div>
  528. <div class="md-footer-nav__title">
  529. <div class="md-ellipsis">
  530. <span class="md-footer-nav__direction">
  531. Previous
  532. </span>
  533. Presentation
  534. </div>
  535. </div>
  536. </a>
  537. <a href="../shapereference/" title="Shapes Reference" class="md-footer-nav__link md-footer-nav__link--next" rel="next">
  538. <div class="md-footer-nav__title">
  539. <div class="md-ellipsis">
  540. <span class="md-footer-nav__direction">
  541. Next
  542. </span>
  543. Shapes Reference
  544. </div>
  545. </div>
  546. <div class="md-footer-nav__button md-icon">
  547. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 11v2h12l-5.5 5.5 1.42 1.42L19.84 12l-7.92-7.92L10.5 5.5 16 11H4z"/></svg>
  548. </div>
  549. </a>
  550. </nav>
  551. </div>
  552. <div class="md-footer-meta md-typeset">
  553. <div class="md-footer-meta__inner md-grid">
  554. <div class="md-footer-copyright">
  555. Made with
  556. <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
  557. Material for MkDocs
  558. </a>
  559. </div>
  560. </div>
  561. </div>
  562. </footer>
  563. </div>
  564. <script src="../assets/javascripts/vendor.c3dc8c49.min.js"></script>
  565. <script src="../assets/javascripts/bundle.f9edbbd5.min.js"></script><script id="__lang" type="application/json">{"clipboard.copy": "Copy to clipboard", "clipboard.copied": "Copied to clipboard", "search.config.lang": "en", "search.config.pipeline": "trimmer, stopWordFilter", "search.config.separator": "[\\s\\-]+", "search.result.placeholder": "Type to start searching", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents"}</script>
  566. <script>
  567. app = initialize({
  568. base: "..",
  569. features: [],
  570. search: Object.assign({
  571. worker: "../assets/javascripts/worker/search.8e2cddea.min.js"
  572. }, typeof search !== "undefined" && search)
  573. })
  574. </script>
  575. <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML"></script>
  576. </body>
  577. </html>