| 1 | from math import * |
| 2 | |
| 3 | def plot_elastica(a, c): |
| 4 | s = 500 |
| 5 | cmd = 'moveto' |
| 6 | dx = .001 |
| 7 | x, y = 0, 0 |
| 8 | if c * c > 2 * a * a: |
| 9 | g = sqrt(c * c - 2 * a * a) |
| 10 | x = g + .01 |
| 11 | if c == 0: |
| 12 | x = .001 |
| 13 | try: |
| 14 | for i in range(1000): |
| 15 | print 6 + s * x, 200 + s * y, cmd |
| 16 | cmd = 'lineto' |
| 17 | x += dx |
| 18 | if 1 and c * c > 2 * a * a: |
| 19 | print (c * c - x * x) * (x * x - g * g) |
| 20 | dy = dx * (x * x - .5 * c * c - .5 * g * g) / sqrt((c * c - x * x) * (x * x - g * g)) |
| 21 | else: |
| 22 | dy = dx * (a * a - c * c + x * x)/sqrt((c * c - x * x) * (2 * a * a - c * c + x * x)) |
| 23 | y += dy |
| 24 | except ValueError, e: |
| 25 | pass |
| 26 | print 'stroke' |
| 27 | |
| 28 | plot_elastica(1, 0) |
| 29 | print 'showpage' |