• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /macosx-10.10.1/pyobjc-45/pyobjc/pyobjc-framework-Cocoa-2.5.1/Examples/AppKit/FieldGraph/
1from Foundation import NSObject
2from objc import *
3from AppKit import NSBezierPath
4
5from fieldMath import *
6
7#____________________________________________________________
8class CGraphModel(NSObject):
9
10    def init(self):
11        self.field = [1.0, 1.12, 0.567]
12        self.phase = [degToRad(0), degToRad(152.6), degToRad(312.9-360)]
13        self.RMSGain = 0
14        self.spacing = degToRad(90)
15        return self
16
17    def getGraph(self):
18        path = NSBezierPath.bezierPath()
19
20        maxMag = 0
21        mag = self.fieldValue(0)
22
23        maxMag = max(maxMag, mag)
24        path.moveToPoint_(polarToRect((mag, 0)))
25        for deg in range(1, 359, 1):
26            r = (deg/180.0)*pi
27            mag = self.fieldValue(r)
28            maxMag = max(maxMag, mag)
29            path.lineToPoint_(polarToRect((mag, r)))
30        path.closePath()
31
32        return path, maxMag;
33
34    def fieldGain(self):
35        gain = 0
36        Et = self.field[0] + self.field[1] + self.field[2]
37        if Et:          # Don't want to divide by zero in the pathological case
38            spacing = [0, self.spacing, 2*self.spacing]
39
40            # This could easily be optimized--but this is just anexample :-)
41            for i in range(3):
42                for j in range(3):
43                    gain += self.field[i]*self.field[j] * cos(self.phase[j]-self.phase[i]) * bessel(spacing[j]-spacing[i])
44            gain = sqrt(gain) / Et
45
46        self.RMSGain = gain
47        return gain
48
49    def fieldValue(self, a):
50        # The intermedate values are used to more closely match standard field equations nomenclature
51        E0 = self.field[0]
52        E1 = self.field[1]
53        E2 = self.field[2]
54        B0 = self.phase[0]
55        B1 = self.phase[1] + self.spacing * cos(a)
56        B2 = self.phase[2] + 2 * self.spacing * cos(a)
57
58        phix = sin(B0) * E0  + sin(B1) * E1 + sin(B2) * E2
59        phiy = cos(B0) * E0 + cos(B1) * E1 + cos(B2) * E2
60        mag = hypot(phix, phiy)
61
62        return mag
63
64
65    def setField(self, tower, field):
66        self.field[tower] = field
67
68    def getField(self, tower):
69        return self.field[tower]
70
71    def setPhase(self, tower, phase):
72        self.phase[tower] = phase
73
74    def getPhase(self, tower):
75        return self.phase[tower]
76
77    def setSpacing(self, spacing):
78        self.spacing = spacing
79
80    def getSpacing(self):
81        return self.spacing
82