from piscript.PiModule import * import math init("cornu.eps", 100, 100) def fresnel(x): return [math.cos(x*x), math.sin(x*x)] beginpage() center() scale(42) gsave() newpath() for i in range(-1,2): moveto(-1.25, i) lineto(1.25, i) moveto(i, -1.25) lineto(i, 1.25) stroke(0.8) grestore() """ plotting a path integral F(T) = \int_{0}^{T} f(t) dt A perfect setup for Bezier, since F' = f is given in advance DF = [ f(t) + 4 f(t+dt/2) + f(t+dt)] [ dt / 6 ] i.e. uses Simpson's rule there is a square root of pi built into the Bezier construction """ # goes through N cycles of M segments each N=20 M=4 for k in range(2): gsave() # X Y = position, x y = speed X = 0 Y = 0 g = 1 setgray(g) q = 0.97 for i in range(N*M): t = math.sqrt((2*math.pi*i)/M) nt = math.sqrt((2*math.pi*(i+1))/M) f = fresnel(t) x = f[0]; y = f[1] dt = nt-t # now build one Bezier segment newpath() moveto(X, Y) X1 = X + x*dt/3.0 Y1 = Y + y*dt/3.0 f1 = fresnel(t+0.5*dt) x1 = f1[0]; y1 = f1[1] t += dt f2 = fresnel(t) x2 = f2[0]; y2 = f2[1] X += (x + 4*x1 + x2)*dt/6.0 Y += (y + 4*y1 + y2)*dt/6.0 X2 = X - x2*dt/3.0 Y2 = Y - y2*dt/3.0 curveto(X1, Y1, X2, Y2, X, Y) stroke(1-g) g *= q scalelinewidth(0.9) grestore() rotate(math.pi) translate(-0.92, 0.18) setcolor(0.8, 0, 0) scale(0.025) place(texinsert("Cornu spiral")) endpage() flush()