/[gzz]/gzz/lava/gfx/shopt/smcurv.py
ViewVC logotype

Diff of /gzz/lava/gfx/shopt/smcurv.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by tjl, Sat Aug 24 18:39:31 2002 UTC revision 1.3 by tjl, Wed Aug 28 12:00:44 2002 UTC
# Line 9  from Scientific.Functions.FirstDerivativ Line 9  from Scientific.Functions.FirstDerivativ
9    
10  class SmoothCurve:  class SmoothCurve:
11      def addWidgets(self, parent):      def addWidgets(self, parent):
12          pass          frame = Frame(parent)
13            slider(self, "eqdist", DoubleVar(), 0.1, 0, 1, parent=frame)
14            slider(self, "kdist", DoubleVar(), 1, 0, 10, parent=frame)
15            slider(self, "distexp", DoubleVar(), 2, 0, 10, parent=frame, resolution=2)
16            slider(self, "kcurv", DoubleVar(), 1, 0, 10, parent=frame)
17            slider(self, "curvexp", DoubleVar(), 1, 0, 10, parent=frame)
18            slider(self, "xoffs", DoubleVar(), 1, 0, 5, parent=frame)
19            frame.pack(expand=1, fill="both")
20    
21      def reset(self, dice):      def reset(self, dice):
22          self.dice = dice          self.dice = dice
23      def defaultX(self):      def defaultX(self):
24          step = 1.0 / self.dice          step = 1.0 / self.dice
25          rang = arrayrange(0, 1 + step, step)          rang = arrayrange(0, 1 + self.dice) / (self.dice + 0.0)
26          self.l = rang[NewAxis, :]          self.l = rang[NewAxis, :]
27    
28          self.matrix = cos(math.pi * rang * (arange(rang.shape[0]) [:, NewAxis] ))          x = concatenate( (0.1*self.l, 0.05 + 0.0 * self.l ) )
29            x[1,0] = 0
30          return concatenate( (0.1*self.l, 0.1 * self.l * self.l) )          x[1,-1] = 0.1
31            x[0,1] = 0.0
32            x[0,-2] = 0.1
33            return x
34      def __call__(self, v):      def __call__(self, v):
35          # print "V:",v          # print "V:",v
36            eqdist = self.eqdist.get()
37            kdist = self.kdist.get()
38            kcurv = self.kcurv.get()
39            xoffs = self.xoffs.get()
40            distexp = self.distexp.get()
41            curvexp = self.curvexp.get()
42            v[0,-1] = xoffs
43            v[0,-2] = xoffs
44    
45          # def scalarsinglepot(x):          # def scalarsinglepot(x):
46          def scalarneighpot(x1, y1, x2, y2):          def scalarneighpot(x1, y1, x2, y2):
47              # return 1 * (sqrt((x2-x1)**2 + (y2-y1)**2)/self.dice - 1.0)**2 / self.dice              # return 1 * (sqrt((x2-x1)**2 + (y2-y1)**2)/self.dice - 1.0)**2 / self.dice
48              return 200 * ((x2-x1)**2 + (y2-y1)**2)              dist = sqrt((x2-x1)**2 + (y2-y1)**2)
49                return kdist * ((dist*self.dice-eqdist)**distexp)/self.dice
50          def scalardneighpot(x1, y1, x2, y2, x3, y3):          def scalardneighpot(x1, y1, x2, y2, x3, y3):
51              # Calculate angle of turning              # Calculate angle of turning
52              #return 0*x3              #return 0*x3
# Line 34  class SmoothCurve: Line 54  class SmoothCurve:
54              dx2 = (x3-x2)              dx2 = (x3-x2)
55              dy1 = (y2-y1)              dy1 = (y2-y1)
56              dy2 = (y3-y2)              dy2 = (y3-y2)
57              l1 = sqrt(dx1**2+dy1**2)              l1sq = (dx1**2+dy1**2)
58              l2 = sqrt(dx2**2+dy2**2)              l2sq = (dx2**2+dy2**2)
59              dot = (dx1*dx2 + dy1*dy2)/l1/l2              dot = (dx1*dx2 + dy1*dy2)
60              return ((1-dot))                cosangle = dot / (sqrt(l1sq * l2sq+0.00001))
61                return kcurv * (1 - cosangle) ** curvexp
62                # (((l1sq+l2sq-2*dot)))
63    
64          grad = v*0          grad = v*0
65    
# Line 78  class SmoothCurve: Line 100  class SmoothCurve:
100    
101          grad[:,0] = 0          grad[:,0] = 0
102          grad[:,-1] = 0          grad[:,-1] = 0
103            grad[0,1] = 0
104            grad[0,-2] = 0
105            # Then, set the gradients so that the second and second-last points move towards
106            # the vertical line
107            # grad[0,1] = 10000 * (v[0,1]-v[0,0])
108    #       grad[0,-2] = 10000 * (v[0,-2]-v[0,-1])
109    #       artifu = 10000 * (0.5* (v[0,1]-v[0,0])**2 +  0.5*(v[0,-2]-v[0,-1])**2)
110            
111    
112          return (sum(ravel(gs[0]) + sum(ravel(gss[0]))), grad)          return (sum(ravel(gs[0]) + sum(ravel(gss[0]))), grad)
113    
114      def plot(self, v):      def plot(self, v):
115          writegeom(gvline(v[0,:], v[1,:]), 0)          writegeom(gvline(v[0,:], v[1,:]), 0)
116    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26