9 |
def __init__(self, vs, center, radius, p, nadir): |
def __init__(self, vs, center, radius, p, nadir): |
10 |
self.vs, self.c, self.r, self.p, self.nadir = vs, center, radius, p, nadir |
self.vs, self.c, self.r, self.p, self.nadir = vs, center, radius, p, nadir |
11 |
self.linecon = GLRen.createLineConnector(0, 0) |
self.linecon = GLRen.createLineConnector(0, 0) |
12 |
def addBuoy(self, anchorX, anchorY, importance, key, buoy, w, h): |
def addBuoy(self, anchorX, anchorY, importance, key, w, h): |
13 |
size = importance |
size = importance |
14 |
|
|
15 |
# 1. find the projected buoy point |
# 1. find the projected buoy point |
23 |
# Coefficients of the 2nd degree eq |
# Coefficients of the 2nd degree eq |
24 |
a = v[0]*v[0] + v[1]*v[1] |
a = v[0]*v[0] + v[1]*v[1] |
25 |
b = 2*(v[0]*AmC[0] + v[1]*AmC[1]) |
b = 2*(v[0]*AmC[0] + v[1]*AmC[1]) |
26 |
c = AmC[0]*AmC[0] + AmC[1]+AmC[1] - self.r**2 |
c = AmC[0]*AmC[0] + AmC[1]*AmC[1] - self.r**2 |
27 |
|
|
28 |
print "S: ",v,AmC,self.r, a,b,c |
print "S: ",v,AmC,self.r, a,b,c |
29 |
|
|
32 |
if det <= 0: |
if det <= 0: |
33 |
# For now, ignore |
# For now, ignore |
34 |
print "Ignoring ",key |
print "Ignoring ",key |
35 |
return |
b = (0,0) |
36 |
|
|
37 |
ans = (-b + math.sqrt(det)) / (2*a) |
else: |
|
print "DA: ",det,ans |
|
38 |
|
|
39 |
b = (self.p[0] + ans * v[0], self.p[1] + ans * v[1]) |
ans = (-b + math.sqrt(det)) / (2*a) |
40 |
print "Buoy: (%s,%s): (%s,%s)\n"%( |
print "DA: ",det,ans |
41 |
anchorX, anchorY, b[0], b[1]) |
|
42 |
|
b = (self.p[0] + ans * v[0], self.p[1] + ans * v[1]) |
43 |
|
print "Buoy: (%s,%s): (%s,%s)\n"%( |
44 |
|
anchorX, anchorY, b[0], b[1]) |
45 |
|
|
46 |
# Create the coordinate system |
# Create the coordinate system |
47 |
|
|
48 |
vs = self.vs |
vs = self.vs |
49 |
transaffine(vs, str(key)+"_1", b[0], b[1], size, 0, 0, size) |
cs1 = vs.coords.affineCoordsys(0, 50, b[0], b[1], size, 0, 0, size) |
50 |
rotate(vs, str(key)+"_2", 360 * self.nadir.getAngleRad(b[0], b[1]) / |
vs.matcher.add(cs1, str(key)+"_buo_1") |
51 |
(2 * math.pi), 0, 0, 1) |
cs2 = vs.coords.rotateXY(cs1, 360 * self.nadir.getAngleRad(b[0], b[1]) / (2 * math.pi)) |
52 |
buoy.run() |
vs.matcher.add(cs2,str(key)+"_buo_2") |
53 |
poptrans(vs, str(key)+"_2") |
return cs2 |
54 |
poptrans(vs, str(key)+"_1") |
|
55 |
|
# ac = vs.coords.coordsys(0, str(key)+"_5", 10, anchorX, anchorY, 0, 0) |
56 |
ac = vs.coords.coordsys(0, str(key)+"_5", 10, anchorX, anchorY, 0, 0) |
# bc = vs.coords.coordsys(0, str(key)+"_6", 10, b[0], b[1], 0, 0) |
57 |
bc = vs.coords.coordsys(0, str(key)+"_6", 10, b[0], b[1], 0, 0) |
# vs.map.put(self.linecon, ac, bc) |
58 |
vs.map.put(self.linecon, ac, bc) |
def addCentralBuoy(self, key): |
59 |
|
b = self.c |
60 |
|
size = 1 |
61 |
|
vs = self.vs |
62 |
|
cs = vs.coords.affineCoordsys(0, 100, b[0], b[1], size, 0, 0, size) |
63 |
|
vs.matcher.add(cs, str(key)+"_buo_1") |
64 |
|
|
65 |
|
cs2 = vs.coords.rotateXY(cs, 0) |
66 |
|
vs.matcher.add(cs2, str(key)+"_buo_2") |
67 |
|
return cs2 |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
# Prototype: just start from the middle, then up & down |
# Prototype: just start from the middle, then up & down |