Hans Petter Langtangen 10 年之前
父节点
当前提交
216f709080
共有 10 个文件被更改,包括 30 次插入95 次删除
  1. 10 0
      README.do.txt
  2. 11 0
      README.md
  3. 7 3
      doc/src/tut/classes.do.txt
  4. 二进制
      examples/pendulum.pdf
  5. 二进制
      examples/pendulum.png
  6. 2 92
      examples/pendulum.py
  7. 二进制
      examples/pendulum2.pdf
  8. 二进制
      examples/pendulum2.png
  9. 二进制
      examples/pendulum_body_diagram.pdf
  10. 二进制
      examples/pendulum_body_diagram.png

+ 10 - 0
README.do.txt

@@ -36,6 +36,16 @@ FIGURE: [http://hplgit.github.io/bumpy/doc/src/mov-bumpy/m2_k1_5_b0_2/tmp_frame_
 For an introduction to Pysketcher, see the tutorial in "HTML": "http://hplgit.github.io/pysketcher/doc/pub/pysketcher.html", "Sphinx": "http://hplgit.github.io/pysketcher/doc/pub/html/index.html", or "PDF": "http://hplgit/github.io/pysketcher/doc/pub/pysketcher.pdf" format (or a simplified version of
 For an introduction to Pysketcher, see the tutorial in "HTML": "http://hplgit.github.io/pysketcher/doc/pub/pysketcher.html", "Sphinx": "http://hplgit.github.io/pysketcher/doc/pub/html/index.html", or "PDF": "http://hplgit/github.io/pysketcher/doc/pub/pysketcher.pdf" format (or a simplified version of
 the tutorial in Chapter 9 in "A Primer on Scientific Programming with Python": "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", by H. P. Langtangen, Springer, 2014).
 the tutorial in Chapter 9 in "A Primer on Scientific Programming with Python": "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", by H. P. Langtangen, Springer, 2014).
 
 
+===== Examples =====
+
+See the `examples` directory for some examples.
+For example, a pendulum and its body diagram,
+
+FIGURE: [examples/pendulum2, width=800 frac=1]
+
+can be created by the "`examples/pendulum.py`": "https://github.com/hplgit/pysketcher/tree/master/examples/pendulum.py".
+
+
 ===== Citation =====
 ===== Citation =====
 
 
 If you use Pysketcher and want to cite it, you can either cite this
 If you use Pysketcher and want to cite it, you can either cite this

+ 11 - 0
README.md

@@ -40,6 +40,17 @@ other objects in the vehicle, [view animation](http://hplgit.github.io/bumpy/doc
 For an introduction to Pysketcher, see the tutorial in [HTML](http://hplgit.github.io/pysketcher/doc/pub/pysketcher.html), [Sphinx](http://hplgit.github.io/pysketcher/doc/pub/html/index.html), or [PDF](http://hplgit/github.io/pysketcher/doc/pub/pysketcher.pdf) format (or a simplified version of
 For an introduction to Pysketcher, see the tutorial in [HTML](http://hplgit.github.io/pysketcher/doc/pub/pysketcher.html), [Sphinx](http://hplgit.github.io/pysketcher/doc/pub/html/index.html), or [PDF](http://hplgit/github.io/pysketcher/doc/pub/pysketcher.pdf) format (or a simplified version of
 the tutorial in Chapter 9 in [A Primer on Scientific Programming with Python](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), by H. P. Langtangen, Springer, 2014).
 the tutorial in Chapter 9 in [A Primer on Scientific Programming with Python](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), by H. P. Langtangen, Springer, 2014).
 
 
+### Examples
+
+See the `examples` directory for some examples.
+For example, a pendulum and its body diagram,
+
+<!-- <img src="examples/pendulum2.png" width=800> -->
+![](examples/pendulum2.png)
+
+can be created by the [`examples/pendulum.py`](https://github.com/hplgit/pysketcher/tree/master/examples/pendulum.py).
+
+
 ### Citation
 ### Citation
 
 
 If you use Pysketcher and want to cite it, you can either cite this
 If you use Pysketcher and want to cite it, you can either cite this

+ 7 - 3
doc/src/tut/classes.do.txt

@@ -5,6 +5,9 @@ This section presents many of the basic shapes in Pysketcher:
 `Spring`, `Dashpot`, and `Wavy`.
 `Spring`, `Dashpot`, and `Wavy`.
 Each shape is demonstrated with a figure and a
 Each shape is demonstrated with a figure and a
 unit test that shows how the figure is constructed in Python code.
 unit test that shows how the figure is constructed in Python code.
+These demos rely heavily on the method `draw_dimensions` in
+the shape classes, which annotates the basic drawing of the shape
+with the various geometric parameters that govern the shape.
 
 
 
 
 ===== Axis =====
 ===== Axis =====
@@ -62,8 +65,9 @@ The above figure can be produced by the following code.
 
 
 @@@CODE ../../../pysketcher/shapes.py fromto: def test_Rectangle@drawing_tool.savefig\('tmp_Rectangle
 @@@CODE ../../../pysketcher/shapes.py fromto: def test_Rectangle@drawing_tool.savefig\('tmp_Rectangle
 
 
-The `draw_dimension` method adds explanation of dimensions and various
-important argument in the construction of a shape.
+Note that the `draw_dimension` method adds explanation of dimensions and various
+important argument in the construction of a shape. It adapts the annotations
+to the geometry of the current shape.
 
 
 ===== Triangle =====
 ===== Triangle =====
 
 
@@ -98,7 +102,7 @@ FIGURE: [fig-tut/Spring, width=800 frac=1]
 <linebreak>
 <linebreak>
 <linebreak>
 <linebreak>
 
 
-The code for making this spring is
+The code for making these two springs goes like this:
 
 
 @@@CODE ../../../pysketcher/shapes.py fromto: def test_Spring@drawing_tool.savefig\('tmp_Spring
 @@@CODE ../../../pysketcher/shapes.py fromto: def test_Spring@drawing_tool.savefig\('tmp_Spring
 
 

二进制
examples/pendulum.pdf


二进制
examples/pendulum.png


+ 2 - 92
examples/pendulum.py

@@ -1,92 +1,2 @@
-from pysketcher import *
-
-H = 7.
-W = 6.
-
-drawing_tool.set_coordinate_system(xmin=0, xmax=W,
-                                   ymin=0, ymax=H,
-                                   axis=False)
-drawing_tool.set_linecolor('blue')
-#drawing_tool.set_grid(True)
-
-def set_dashed_thin_blackline(*objects):
-    """Set linestyle of an object to dashed, black, width=1."""
-    for obj in objects:
-        obj.set_linestyle('dashed')
-        obj.set_linecolor('black')
-        obj.set_linewidth(1)
-
-
-L = 5*H/7          # length
-P = (W/6, 0.85*H)  # rotation point
-a = 40             # angle
-
-path = Arc(P, L, -90, a)
-angle = Arc_wText(r'$\theta$', P, L/4, -90, a, text_spacing=1/30.)
-vertical = Line(P, P-point(0,L))
-
-rod = Line(P, P + L*point(sin(radians(a)), -L*cos(radians(a))))
-# or shorter (and more reliable)
-mass_pt = path.geometric_features()['end']
-rod = Line(P, mass_pt)
-
-mass = Circle(center=mass_pt, radius=L/20.)
-mass.set_filled_curves(color='blue')
-rod_vec = rod.geometric_features()['end'] - rod.geometric_features()['start']
-mass_symbol = Text('$m$', mass_pt + L/10*unit_vec(rod_vec))
-
-length = Distance_wText(P, mass_pt, '$L$')
-# Displace length indication
-length.translate(L/15*point(cos(radians(a)), sin(radians(a))))
-gravity = Gravity(start=P+point(0.8*L,0), length=L/3)
-
-set_dashed_thin_blackline(vertical, path)
-
-dims = Composition(
-    {'vertical': vertical, 'theta': angle, 'path': path,
-     'g': gravity, 'L': length, 'm': mass_symbol})
-
-fig = Composition({'body': mass, 'rod': rod, 'dims': dims})
-
-#drawing_tool.ax.set_xlim(4,10)
-#drawing_tool.ax.set_ylim(1,8)
-fig.draw()
-drawing_tool.display()
-drawing_tool.savefig('tmp_pendulum1')
-
-# Draw body diagram
-raw_input('Press Return to make body diagram: ')
-#import time; time.sleep(3)
-drawing_tool.erase()
-
-drawing_tool.set_linecolor('black')
-mg_force = Force(mass_pt, mass_pt + L/5*point(0,-1), '$mg$', text_pos='end')
-rod_force = Force(mass_pt, mass_pt - L/3*unit_vec(rod_vec),
-                  '$S$', text_pos='end')
-
-rod_start = rod.geometric_features()['start']
-vertical2 = Line(rod_start, rod_start + point(0,-L/3))
-set_dashed_thin_blackline(vertical2)
-set_dashed_thin_blackline(rod)
-angle2 = Arc_wText(r'$\theta$', rod_start, L/6, -90, a, text_spacing=1/30.)
-
-# Cannot understand this one:
-#path2 = Arc(P, L, -90+a-a/2., a)
-#path2.set_arrow('<-')
-#path2.set_linestyle('dashed')
-
-body_diagram = Composition(
-    {'mg': mg_force, 'S': rod_force, 'rod': rod,
-     'vertical': vertical2, 'theta': angle2,
-     #'path': path2,
-     'body': mass, 'm': mass_symbol})
-
-body_diagram.draw()
-drawing_tool.display('Body diagram')
-drawing_tool.savefig('tmp_pendulum2')
-
-drawing_tool.adjust_coordinate_system(body_diagram.minmax_coordinates(), 90)
-drawing_tool.display('Body diagram')
-drawing_tool.savefig('tmp_pendulum3')
-
-raw_input()
+# See pysketcher/examples/pendulum.py for code that produced the
+# pendulum figures.

二进制
examples/pendulum2.pdf


二进制
examples/pendulum2.png


二进制
examples/pendulum_body_diagram.pdf


二进制
examples/pendulum_body_diagram.png