Ver Fonte

YAML Sketcher Grammar in User Guide

Gilbert Brault há 5 anos atrás
pai
commit
dd34a0fdb4

+ 97 - 0
jupysketch-doc/docs/reference/dryfriction.yml

@@ -0,0 +1,97 @@
+!!omap
+- name: unknown
+- parts:
+  - name: head
+    shapes:
+      libraries: ['from math import tan, radians, sin, cos', from pysketcher import
+          *]
+  - name: constants
+    shapes:
+      fontsize: 18       # size of the characters
+      g: 9.81            # constant gravity
+      theta: 30.0        # inclined plane angle
+      L: 10.0            # sketch sizing parameter
+      a: 1.0             #
+      xmin: 0.0          # sketech min Abscissa
+      ymin: -3.0         # sketech min Ordinate     
+      rl: 2.0            # rectangle width
+      rL: 1.0            # rectangle length
+  - name: frame
+    shapes:
+      setframe:          # sketch setup
+        action: 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')
+      setblackline:      # default frame values and actions
+        action: drawing_tool.set_linecolor('black')
+      B: point(a+L,0)                    # wall right end
+      A: point(a,tan(radians(theta))*L)  # wall left end
+      normal_vec: point(sin(radians(theta)),cos(radians(theta)))   # Vector normal to wall
+      tangent_vec: point(cos(radians(theta)),-sin(radians(theta))) # Vector tangent to wall
+      help_line: Line(A,B)               # wall line
+      x: a + 3*L/10.                     # contact point Abscissa
+      y: help_line(x=x)                  # contact point Ordinate
+      contact: point(x, y)               # contact point: middle of the rectangle bottom edge
+      c: contact + rL/2*normal_vec
+  - name: body
+    shapes:
+      rectangle:
+        formula: Rectangle(contact, rl, rL)
+        style:
+          linecolor: blue
+          filled_curves: blue
+        transform: ['rotate(-theta, contact)', translate(-rl/2*tangent_vec)]
+      N:
+        formula: Force(contact - rl*normal_vec, contact, r'$N$', text_pos='start')
+        style:
+          linecolor: black
+      wheel:
+        formula: "Composition({'outer': rectangle})"
+        style:
+          shadow: 1
+      mc:
+        formula: Text(r'$c$', c)
+      body:
+        formula: "Composition({'wheel': wheel, 'N': N, 'mc': mc})"
+        style:
+          linecolor: black
+  - name: plan
+    shapes:
+      mB:
+        formula: Text(r'$B$',B)
+      mA:
+        formula: Text(r'$A$', A)
+      wall:
+        formula: Wall(x=[A[0], B[0]], y=[A[1], B[1]], thickness=-0.25,transparent=False)
+        style:
+          linecolor: black
+      x_const:
+        formula: Line(contact, contact + point(0,4))
+        style:
+          linestyle: dotted
+        transform: rotate(-theta, contact)
+      x_axis:
+        formula: Axis(start=contact+ 2*rl*normal_vec, length=2*rl,label='$x$', rotation_angle=-theta)
+      plan:
+        formula: "Composition({'body': body, 'inclined wall': wall, 'x start': x_const,\
+          \ 'x axis': x_axis, 'mA': mA, 'mB': mB})"
+  - name: friction
+    shapes:
+      mg:
+        formula: Gravity(c, rl, text='$Mg$')
+        style:
+          linecolor: black
+      angle:
+        formula: Arc_wText(r'$<bslash>theta$', center=B, radius=3, start_angle=180-theta,
+          arc_angle=theta, fontsize=fontsize)
+        style:
+          linecolor: black
+          linewidth: 1
+      ground:
+        formula: Line((B[0]-L/10., 0), (B[0]-L/2.,0))
+        stlye:
+          linecolor: black
+          linestyle: dashed
+          linewidth: 1
+      friction:
+        formula: "Composition({'plan': plan, 'ground': ground, 'mg': mg, 'angle':\
+          \ angle})"

Diff do ficheiro suprimidas por serem muito extensas
+ 3 - 0
jupysketch-doc/docs/reference/yamlpysketchergrammar.svg


Diff do ficheiro suprimidas por serem muito extensas
+ 394 - 615
jupysketch-doc/docs/resources/DryFriction.html


Diff do ficheiro suprimidas por serem muito extensas
+ 1 - 0
jupysketch-doc/docs/resources/yamlpysketchergrammar.drawio


+ 7 - 4
jupysketch-doc/docs/shapereference.md

@@ -324,8 +324,6 @@ gravity.set_name("gravity")
 ```
 ![Gravity](reference/gravity.svg)
 
-## Code to display the above defined shapes
-
 ## Moment
 [home](#list-of-shapes) defines a Moment arrow with text given text, center and radius.
 
@@ -422,6 +420,8 @@ dashpot.set_name("dashpot")
 ```
 ![Dashpot](reference/dashpot.svg)
 
+## Code to display the above defined shapes
+
 [home](#list-of-shapes) In order to display the various shapes, use the following code in a jupyter notebook
 
 
@@ -439,7 +439,8 @@ for Yaml, you need to add those extra steps
 head = """\
 libraries: ["from math import tan, radians, sin, cos","from pysketcher import *","import numpy as np"]
 myfig={}
-sketchParse(head,myfig)
+sketch = Sketch(myfig)
+sketch.append(head)
 ```
 The above code initialize myfig sketch space loading into it libraries references so samples can use tan, radians, si, cos and all the objects defined in pysketcher (the module name of jupytersketcher) and numpy as well: this is used by the yaml definition of shapes
 
@@ -451,10 +452,11 @@ sketch="""
 # put here the yaml 'object' definition
 """
 drawing_tool.erase()
-sketchParse(sketch,myfig)
+sketch.append(sketch)
 # replace 'object' by the actual one
 d = myfig['object'].draw() 
 drawing_tool.display()
+display(SVG(Sketch.matplotlib2SVG()))
 ```
 
 ### Python
@@ -465,4 +467,5 @@ drawing_tool.erase()
 # replace object by the actual name line, rectangle, circle...
 object.draw()
 drawing_tool.display()
+display(SVG(Sketch.matplotlib2SVG()))
 ```

+ 174 - 0
jupysketch-doc/docs/yamlsketcher.md

@@ -0,0 +1,174 @@
+Content
+
+* [YAML sketcher file grammar](#yaml-sketcher-file-grammar)
+* [Libraries, Pysketcher Object creation, Styles, Transform](#libraries-pysketcher-object-creation-styles-transform)
+* [Example](#example)
+* [Code to read or write a yaml sketcher file](#code-to-read-or-write-a-yaml-sketcher-file)
+
+## YAML sketcher file grammar
+
+This is the wireframe grammar:
+
+* starts with S
+* each time you see two "embedded" rectangles, this is the text to write
+* follow the arrows and iterate as needed
+* end with E
+
+![Yaml Sketcher Definition](reference/yamlpysketchergrammar.svg)
+
+## Libraries, Pysketcher Object creation, Styles, Transform
+
+### Libraries
+
+The libraries token defined in the grammar is
+
+* a single import directive
+* a list [] of import directive
+* one of the import must be pysketcher!
+
+```python
+from pysketcher import *
+```
+
+### Pysketcher object creation
+
+* The `Python pysktecher object creation` is a python class object statment. 
+* The possible class are defined in this [section](/shapereference)
+* Every parameter of the object creation can be an expression, based upon variables defined before in the YAML file
+
+### Styles
+
+The list of possible style correspond to the list of set_&lt;style> members of the corresponding pysketcher class used for the object creation. This function will be applied to the current object under creation. Parameters of this function can be variable defined upstream. 
+
+### Transform
+
+The transform token defined in the grammer is
+
+* a single transform statement
+* a list [] of transform statments
+* a tranform statement is a transformation function that can be applied to the object under construction
+* example of transform function are rotate, translate
+* parameters of the transform function can be expression based upon upstream variables definition
+
+## Example
+```yaml
+!!omap
+- name: unknown
+- parts:
+  - name: head
+    shapes:
+      libraries: ['from math import tan, radians, sin, cos', from pysketcher import
+          *]
+  - name: constants
+    shapes:
+      fontsize: 18       # size of the characters
+      g: 9.81            # constant gravity
+      theta: 30.0        # inclined plane angle
+      L: 10.0            # sketch sizing parameter
+      a: 1.0             #
+      xmin: 0.0          # sketech min Abscissa
+      ymin: -3.0         # sketech min Ordinate     
+      rl: 2.0            # rectangle width
+      rL: 1.0            # rectangle length
+  - name: frame
+    shapes:
+      setframe:          # sketch setup
+        action: 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')
+      setblackline:      # default frame values and actions
+        action: drawing_tool.set_linecolor('black')
+      B: point(a+L,0)                    # wall right end
+      A: point(a,tan(radians(theta))*L)  # wall left end
+      normal_vec: point(sin(radians(theta)),cos(radians(theta)))   # Vector normal to wall
+      tangent_vec: point(cos(radians(theta)),-sin(radians(theta))) # Vector tangent to wall
+      help_line: Line(A,B)               # wall line
+      x: a + 3*L/10.                     # contact point Abscissa
+      y: help_line(x=x)                  # contact point Ordinate
+      contact: point(x, y)               # contact point: middle of the rectangle bottom edge
+      c: contact + rL/2*normal_vec
+  - name: body
+    shapes:
+      rectangle:
+        formula: Rectangle(contact, rl, rL)
+        style:
+          linecolor: blue
+          filled_curves: blue
+        transform: ['rotate(-theta, contact)', translate(-rl/2*tangent_vec)]
+      N:
+        formula: Force(contact - rl*normal_vec, contact, r'$N$', text_pos='start')
+        style:
+          linecolor: black
+      wheel:
+        formula: "Composition({'outer': rectangle})"
+        style:
+          shadow: 1
+      mc:
+        formula: Text(r'$c$', c)
+      body:
+        formula: "Composition({'wheel': wheel, 'N': N, 'mc': mc})"
+        style:
+          linecolor: black
+  - name: plan
+    shapes:
+      mB:
+        formula: Text(r'$B$',B)
+      mA:
+        formula: Text(r'$A$', A)
+      wall:
+        formula: Wall(x=[A[0], B[0]], y=[A[1], B[1]], thickness=-0.25,transparent=False)
+        style:
+          linecolor: black
+      x_const:
+        formula: Line(contact, contact + point(0,4))
+        style:
+          linestyle: dotted
+        transform: rotate(-theta, contact)
+      x_axis:
+        formula: Axis(start=contact+ 2*rl*normal_vec, length=2*rl,label='$x$', rotation_angle=-theta)
+      plan:
+        formula: "Composition({'body': body, 'inclined wall': wall, 'x start': x_const,\
+          \ 'x axis': x_axis, 'mA': mA, 'mB': mB})"
+  - name: friction
+    shapes:
+      mg:
+        formula: Gravity(c, rl, text='$Mg$')
+        style:
+          linecolor: black
+      angle:
+        formula: Arc_wText(r'$<bslash>theta$', center=B, radius=3, start_angle=180-theta,
+          arc_angle=theta, fontsize=fontsize)
+        style:
+          linecolor: black
+          linewidth: 1
+      ground:
+        formula: Line((B[0]-L/10., 0), (B[0]-L/2.,0))
+        stlye:
+          linecolor: black
+          linestyle: dashed
+          linewidth: 1
+      friction:
+        formula: "Composition({'plan': plan, 'ground': ground, 'mg': mg, 'angle':\
+          \ angle})"
+```
+
+## Code to read or write a yaml sketcher file
+
+To read a YAML Pysketcher file definition:
+
+```python
+from pysketcher import *
+myfig={}
+sketch = Sketch(myfig)
+sketch.file2Sketch("dryfriction.yml")
+#...............  can now use sketch to draw something ..................
+```
+
+To write a YAML Pysketcher file definition:
+
+```python
+from pysketcher import *
+myfig={}
+sketch = Sketch(myfig)
+#.............  need to create some Pysketcher objects in the sketch .................
+sketch.file2Sketch("dryfriction.yml")
+```

+ 1 - 0
jupysketch-doc/mkdocs.yml

@@ -5,6 +5,7 @@ nav:
     - Presentation: presentation.md
     - Learning by Example: learningbyexample.md
     - Shapes Reference: shapereference.md
+    - YAML files Reference: yamlsketcher.md
 theme:
   name: material
 markdown_extensions:

+ 12 - 0
jupysketch-doc/site/404.html

@@ -200,6 +200,18 @@
   </li>
 
     
+      
+      
+      
+
+
+  <li class="md-nav__item">
+    <a href="/yamlsketcher/" title="YAML files Reference" class="md-nav__link">
+      YAML files Reference
+    </a>
+  </li>
+
+    
   </ul>
 </nav>
                   </div>

+ 12 - 0
jupysketch-doc/site/about/index.html

@@ -207,6 +207,18 @@
   </li>
 
     
+      
+      
+      
+
+
+  <li class="md-nav__item">
+    <a href="../yamlsketcher/" title="YAML files Reference" class="md-nav__link">
+      YAML files Reference
+    </a>
+  </li>
+
+    
   </ul>
 </nav>
                   </div>

+ 12 - 0
jupysketch-doc/site/index.html

@@ -214,6 +214,18 @@
   </li>
 
     
+      
+      
+      
+
+
+  <li class="md-nav__item">
+    <a href="yamlsketcher/" title="YAML files Reference" class="md-nav__link">
+      YAML files Reference
+    </a>
+  </li>
+
+    
   </ul>
 </nav>
                   </div>

+ 12 - 0
jupysketch-doc/site/learningbyexample/index.html

@@ -339,6 +339,18 @@
   </li>
 
     
+      
+      
+      
+
+
+  <li class="md-nav__item">
+    <a href="../yamlsketcher/" title="YAML files Reference" class="md-nav__link">
+      YAML files Reference
+    </a>
+  </li>
+
+    
   </ul>
 </nav>
                   </div>

+ 12 - 0
jupysketch-doc/site/presentation/index.html

@@ -264,6 +264,18 @@
   </li>
 
     
+      
+      
+      
+
+
+  <li class="md-nav__item">
+    <a href="../yamlsketcher/" title="YAML files Reference" class="md-nav__link">
+      YAML files Reference
+    </a>
+  </li>
+
+    
   </ul>
 </nav>
                   </div>

+ 97 - 0
jupysketch-doc/site/reference/dryfriction.yml

@@ -0,0 +1,97 @@
+!!omap
+- name: unknown
+- parts:
+  - name: head
+    shapes:
+      libraries: ['from math import tan, radians, sin, cos', from pysketcher import
+          *]
+  - name: constants
+    shapes:
+      fontsize: 18       # size of the characters
+      g: 9.81            # constant gravity
+      theta: 30.0        # inclined plane angle
+      L: 10.0            # sketch sizing parameter
+      a: 1.0             #
+      xmin: 0.0          # sketech min Abscissa
+      ymin: -3.0         # sketech min Ordinate     
+      rl: 2.0            # rectangle width
+      rL: 1.0            # rectangle length
+  - name: frame
+    shapes:
+      setframe:          # sketch setup
+        action: 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')
+      setblackline:      # default frame values and actions
+        action: drawing_tool.set_linecolor('black')
+      B: point(a+L,0)                    # wall right end
+      A: point(a,tan(radians(theta))*L)  # wall left end
+      normal_vec: point(sin(radians(theta)),cos(radians(theta)))   # Vector normal to wall
+      tangent_vec: point(cos(radians(theta)),-sin(radians(theta))) # Vector tangent to wall
+      help_line: Line(A,B)               # wall line
+      x: a + 3*L/10.                     # contact point Abscissa
+      y: help_line(x=x)                  # contact point Ordinate
+      contact: point(x, y)               # contact point: middle of the rectangle bottom edge
+      c: contact + rL/2*normal_vec
+  - name: body
+    shapes:
+      rectangle:
+        formula: Rectangle(contact, rl, rL)
+        style:
+          linecolor: blue
+          filled_curves: blue
+        transform: ['rotate(-theta, contact)', translate(-rl/2*tangent_vec)]
+      N:
+        formula: Force(contact - rl*normal_vec, contact, r'$N$', text_pos='start')
+        style:
+          linecolor: black
+      wheel:
+        formula: "Composition({'outer': rectangle})"
+        style:
+          shadow: 1
+      mc:
+        formula: Text(r'$c$', c)
+      body:
+        formula: "Composition({'wheel': wheel, 'N': N, 'mc': mc})"
+        style:
+          linecolor: black
+  - name: plan
+    shapes:
+      mB:
+        formula: Text(r'$B$',B)
+      mA:
+        formula: Text(r'$A$', A)
+      wall:
+        formula: Wall(x=[A[0], B[0]], y=[A[1], B[1]], thickness=-0.25,transparent=False)
+        style:
+          linecolor: black
+      x_const:
+        formula: Line(contact, contact + point(0,4))
+        style:
+          linestyle: dotted
+        transform: rotate(-theta, contact)
+      x_axis:
+        formula: Axis(start=contact+ 2*rl*normal_vec, length=2*rl,label='$x$', rotation_angle=-theta)
+      plan:
+        formula: "Composition({'body': body, 'inclined wall': wall, 'x start': x_const,\
+          \ 'x axis': x_axis, 'mA': mA, 'mB': mB})"
+  - name: friction
+    shapes:
+      mg:
+        formula: Gravity(c, rl, text='$Mg$')
+        style:
+          linecolor: black
+      angle:
+        formula: Arc_wText(r'$<bslash>theta$', center=B, radius=3, start_angle=180-theta,
+          arc_angle=theta, fontsize=fontsize)
+        style:
+          linecolor: black
+          linewidth: 1
+      ground:
+        formula: Line((B[0]-L/10., 0), (B[0]-L/2.,0))
+        stlye:
+          linecolor: black
+          linestyle: dashed
+          linewidth: 1
+      friction:
+        formula: "Composition({'plan': plan, 'ground': ground, 'mg': mg, 'angle':\
+          \ angle})"

Diff do ficheiro suprimidas por serem muito extensas
+ 3 - 0
jupysketch-doc/site/reference/yamlpysketchergrammar.svg


Diff do ficheiro suprimidas por serem muito extensas
+ 394 - 615
jupysketch-doc/site/resources/DryFriction.html


Diff do ficheiro suprimidas por serem muito extensas
+ 1 - 0
jupysketch-doc/site/resources/yamlpysketchergrammar.drawio


Diff do ficheiro suprimidas por serem muito extensas
+ 1 - 1
jupysketch-doc/site/search/search_index.json


+ 58 - 17
jupysketch-doc/site/shapereference/index.html

@@ -639,13 +639,6 @@
       </ul>
     </nav>
   
-</li>
-      
-        <li class="md-nav__item">
-  <a href="#code-to-display-the-above-defined-shapes" class="md-nav__link">
-    Code to display the above defined shapes
-  </a>
-  
 </li>
       
         <li class="md-nav__item">
@@ -778,6 +771,19 @@
   
 </li>
         
+      </ul>
+    </nav>
+  
+</li>
+      
+        <li class="md-nav__item">
+  <a href="#code-to-display-the-above-defined-shapes" class="md-nav__link">
+    Code to display the above defined shapes
+  </a>
+  
+    <nav class="md-nav" aria-label="Code to display the above defined shapes">
+      <ul class="md-nav__list">
+        
           <li class="md-nav__item">
   <a href="#yaml_20" class="md-nav__link">
     Yaml
@@ -804,6 +810,18 @@
   </li>
 
     
+      
+      
+      
+
+
+  <li class="md-nav__item">
+    <a href="../yamlsketcher/" title="YAML files Reference" class="md-nav__link">
+      YAML files Reference
+    </a>
+  </li>
+
+    
   </ul>
 </nav>
                   </div>
@@ -1237,13 +1255,6 @@
       </ul>
     </nav>
   
-</li>
-      
-        <li class="md-nav__item">
-  <a href="#code-to-display-the-above-defined-shapes" class="md-nav__link">
-    Code to display the above defined shapes
-  </a>
-  
 </li>
       
         <li class="md-nav__item">
@@ -1376,6 +1387,19 @@
   
 </li>
         
+      </ul>
+    </nav>
+  
+</li>
+      
+        <li class="md-nav__item">
+  <a href="#code-to-display-the-above-defined-shapes" class="md-nav__link">
+    Code to display the above defined shapes
+  </a>
+  
+    <nav class="md-nav" aria-label="Code to display the above defined shapes">
+      <ul class="md-nav__list">
+        
           <li class="md-nav__item">
   <a href="#yaml_20" class="md-nav__link">
     Yaml
@@ -1725,7 +1749,6 @@ gravity.set_name(&quot;gravity&quot;)
 </code></pre>
 
 <p><img alt="Gravity" src="../reference/gravity.svg" /></p>
-<h2 id="code-to-display-the-above-defined-shapes">Code to display the above defined shapes</h2>
 <h2 id="moment">Moment</h2>
 <p><a href="#list-of-shapes">home</a> defines a Moment arrow with text given text, center and radius.</p>
 <h3 id="yaml_15">Yaml</h3>
@@ -1812,6 +1835,7 @@ dashpot.set_name(&quot;dashpot&quot;)
 </code></pre>
 
 <p><img alt="Dashpot" src="../reference/dashpot.svg" /></p>
+<h2 id="code-to-display-the-above-defined-shapes">Code to display the above defined shapes</h2>
 <p><a href="#list-of-shapes">home</a> In order to display the various shapes, use the following code in a jupyter notebook</p>
 <pre><code class="python">[1]: %matplotlib widget
 [2]: from pysketcher import *
@@ -1825,7 +1849,8 @@ dashpot.set_name(&quot;dashpot&quot;)
 <pre><code class="python">head = &quot;&quot;&quot;\
 libraries: [&quot;from math import tan, radians, sin, cos&quot;,&quot;from pysketcher import *&quot;,&quot;import numpy as np&quot;]
 myfig={}
-sketchParse(head,myfig)
+sketch = Sketch(myfig)
+sketch.append(head)
 </code></pre>
 
 <p>The above code initialize myfig sketch space loading into it libraries references so samples can use tan, radians, si, cos and all the objects defined in pysketcher (the module name of jupytersketcher) and numpy as well: this is used by the yaml definition of shapes</p>
@@ -1835,10 +1860,11 @@ sketch=&quot;&quot;&quot;
 # put here the yaml 'object' definition
 &quot;&quot;&quot;
 drawing_tool.erase()
-sketchParse(sketch,myfig)
+sketch.append(sketch)
 # replace 'object' by the actual one
 d = myfig['object'].draw() 
 drawing_tool.display()
+display(SVG(Sketch.matplotlib2SVG()))
 </code></pre>
 
 <h3 id="python_20">Python</h3>
@@ -1847,6 +1873,7 @@ drawing_tool.display()
 # replace object by the actual name line, rectangle, circle...
 object.draw()
 drawing_tool.display()
+display(SVG(Sketch.matplotlib2SVG()))
 </code></pre>
                 
               
@@ -1881,6 +1908,20 @@ drawing_tool.display()
           </a>
         
         
+          <a href="../yamlsketcher/" title="YAML files Reference" class="md-footer-nav__link md-footer-nav__link--next" rel="next">
+            <div class="md-footer-nav__title">
+              <div class="md-ellipsis">
+                <span class="md-footer-nav__direction">
+                  Next
+                </span>
+                YAML files Reference
+              </div>
+            </div>
+            <div class="md-footer-nav__button md-icon">
+              <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>
+            </div>
+          </a>
+        
       </nav>
     </div>
   

+ 9 - 5
jupysketch-doc/site/sitemap.xml

@@ -1,23 +1,27 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url>
      <loc>None</loc>
-     <lastmod>2020-08-06</lastmod>
+     <lastmod>2020-08-07</lastmod>
      <changefreq>daily</changefreq>
     </url><url>
      <loc>None</loc>
-     <lastmod>2020-08-06</lastmod>
+     <lastmod>2020-08-07</lastmod>
      <changefreq>daily</changefreq>
     </url><url>
      <loc>None</loc>
-     <lastmod>2020-08-06</lastmod>
+     <lastmod>2020-08-07</lastmod>
      <changefreq>daily</changefreq>
     </url><url>
      <loc>None</loc>
-     <lastmod>2020-08-06</lastmod>
+     <lastmod>2020-08-07</lastmod>
      <changefreq>daily</changefreq>
     </url><url>
      <loc>None</loc>
-     <lastmod>2020-08-06</lastmod>
+     <lastmod>2020-08-07</lastmod>
+     <changefreq>daily</changefreq>
+    </url><url>
+     <loc>None</loc>
+     <lastmod>2020-08-07</lastmod>
      <changefreq>daily</changefreq>
     </url>
 </urlset>

BIN
jupysketch-doc/site/sitemap.xml.gz


Diff do ficheiro suprimidas por serem muito extensas
+ 645 - 0
jupysketch-doc/site/yamlsketcher/index.html


Diff do ficheiro suprimidas por serem muito extensas
+ 49 - 143
notebooks/.ipynb_checkpoints/DryFriction-checkpoint.ipynb


Diff do ficheiro suprimidas por serem muito extensas
+ 64 - 293
notebooks/DryFriction.ipynb


Diff do ficheiro suprimidas por serem muito extensas
+ 10774 - 803
notebooks/Reference.ipynb


+ 97 - 0
notebooks/dryfriction.yml

@@ -0,0 +1,97 @@
+!!omap
+- name: unknown
+- parts:
+  - name: head
+    shapes:
+      libraries: ['from math import tan, radians, sin, cos', from pysketcher import
+          *]
+  - name: constants
+    shapes:
+      fontsize: 18       # size of the characters
+      g: 9.81            # constant gravity
+      theta: 30.0        # inclined plane angle
+      L: 10.0            # sketch sizing parameter
+      a: 1.0             #
+      xmin: 0.0          # sketech min Abscissa
+      ymin: -3.0         # sketech min Ordinate     
+      rl: 2.0            # rectangle width
+      rL: 1.0            # rectangle length
+  - name: frame
+    shapes:
+      setframe:          # sketch setup
+        action: 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')
+      setblackline:      # default frame values and actions
+        action: drawing_tool.set_linecolor('black')
+      B: point(a+L,0)                    # wall right end
+      A: point(a,tan(radians(theta))*L)  # wall left end
+      normal_vec: point(sin(radians(theta)),cos(radians(theta)))   # Vector normal to wall
+      tangent_vec: point(cos(radians(theta)),-sin(radians(theta))) # Vector tangent to wall
+      help_line: Line(A,B)               # wall line
+      x: a + 3*L/10.                     # contact point Abscissa
+      y: help_line(x=x)                  # contact point Ordinate
+      contact: point(x, y)               # contact point: middle of the rectangle bottom edge
+      c: contact + rL/2*normal_vec
+  - name: body
+    shapes:
+      rectangle:
+        formula: Rectangle(contact, rl, rL)
+        style:
+          linecolor: blue
+          filled_curves: blue
+        transform: ['rotate(-theta, contact)', translate(-rl/2*tangent_vec)]
+      N:
+        formula: Force(contact - rl*normal_vec, contact, r'$N$', text_pos='start')
+        style:
+          linecolor: black
+      wheel:
+        formula: "Composition({'outer': rectangle})"
+        style:
+          shadow: 1
+      mc:
+        formula: Text(r'$c$', c)
+      body:
+        formula: "Composition({'wheel': wheel, 'N': N, 'mc': mc})"
+        style:
+          linecolor: black
+  - name: plan
+    shapes:
+      mB:
+        formula: Text(r'$B$',B)
+      mA:
+        formula: Text(r'$A$', A)
+      wall:
+        formula: Wall(x=[A[0], B[0]], y=[A[1], B[1]], thickness=-0.25,transparent=False)
+        style:
+          linecolor: black
+      x_const:
+        formula: Line(contact, contact + point(0,4))
+        style:
+          linestyle: dotted
+        transform: rotate(-theta, contact)
+      x_axis:
+        formula: Axis(start=contact+ 2*rl*normal_vec, length=2*rl,label='$x$', rotation_angle=-theta)
+      plan:
+        formula: "Composition({'body': body, 'inclined wall': wall, 'x start': x_const,\
+          \ 'x axis': x_axis, 'mA': mA, 'mB': mB})"
+  - name: friction
+    shapes:
+      mg:
+        formula: Gravity(c, rl, text='$Mg$')
+        style:
+          linecolor: black
+      angle:
+        formula: Arc_wText(r'$<bslash>theta$', center=B, radius=3, start_angle=180-theta,
+          arc_angle=theta, fontsize=fontsize)
+        style:
+          linecolor: black
+          linewidth: 1
+      ground:
+        formula: Line((B[0]-L/10., 0), (B[0]-L/2.,0))
+        stlye:
+          linecolor: black
+          linestyle: dashed
+          linewidth: 1
+      friction:
+        formula: "Composition({'plan': plan, 'ground': ground, 'mg': mg, 'angle':\
+          \ angle})"

notebooks/fourbar.png → notebooks/other examples/fourbar.png


+ 21 - 2
pysketcher/shapes.py

@@ -67,8 +67,27 @@ class Sketch():
             if name not in self.container:
                 return f"{sketch}/{key}: {name} in {expression} is not defined"
         return 1
+
+    def sketch2File(self, filePath):
+        """
+        dump a sketch to file
+        """
+        yaml = YAML()
+        file = open(filePath,"w")
+        yaml.dump(self.sketch,file)
+        file.close()
+    
+    def file2Sketch(self,filePath):
+        """
+        load a sketch from file
+        """
+        yaml = YAML()
+        file = open(filePath, "r")
+        sketchstring = file.read()
+        file.close()
+        return self.string2Sketch(sketchstring)
     
-    def getSketch(self):
+    def sketch2String(self):
         """
         dump sketch as a string
         """
@@ -77,7 +96,7 @@ class Sketch():
         yaml.dump(self.sketch,f)
         return f.getvalue()
 
-    def loadSketch(self,sketchstring):
+    def string2Sketch(self,sketchstring):
         """
         load a sketch from string
         """