22 |
for i in range(0,4) ] |
for i in range(0,4) ] |
23 |
if 120 - self._AB_angle(col) > 90 * rnd.nextFloat(): break |
if 120 - self._AB_angle(col) > 90 * rnd.nextFloat(): break |
24 |
#if self._AB_angle(col) < 180: break |
#if self._AB_angle(col) < 180: break |
25 |
print self._AB_angle(col) |
print "ANGLE=", self._AB_angle(col), "AREA=", self._AB_area(col)*100 |
26 |
|
|
27 |
while 0: |
while 0: |
28 |
col = [ |
col = [ |
86 |
|
|
87 |
return reduce(lambda x,y: x+y, dots) / len(dots) |
return reduce(lambda x,y: x+y, dots) / len(dots) |
88 |
|
|
89 |
def _AB_area(seld, cols): |
def _AB_area(self, cols): |
90 |
pass |
ab = [ (lab[1]/100.0,lab[2]/100.0) for lab in map(RGBtoLAB, cols) ] |
91 |
|
#print [ (int(100*a),int(100*b)) for (a,b) in ab ] |
92 |
|
ab = convex_hull(ab) |
93 |
|
#print [ (int(100*a),int(100*b)) for (a,b) in ab ] |
94 |
|
return polygon_area(ab) |
95 |
|
|
96 |
|
def polygon_area(pts): |
97 |
|
A = 0 |
98 |
|
for i in range(0, len(pts)): |
99 |
|
A += pts[i-1][0] * pts[i][1] - pts[i][0] * pts[i-1][1] |
100 |
|
return A |
101 |
|
|
102 |
|
def convex_hull(pts): |
103 |
|
if len(pts) < 2: return pts |
104 |
|
pts.sort() |
105 |
|
|
106 |
|
#print "P=", [ (int(100*a),int(100*b)) for (a,b) in pts ] |
107 |
|
|
108 |
|
def dir(p,q,r): |
109 |
|
"""Return positive if p,q,r turns cw, neg if ccw, zero if linear.""" |
110 |
|
return (q[1]-p[1])*(r[0]-p[0]) - (q[0]-p[0])*(r[1]-p[1]) |
111 |
|
|
112 |
|
|
113 |
|
U = pts[0:2] |
114 |
|
L = pts[0:2] |
115 |
|
|
116 |
|
for p in pts[2:]: |
117 |
|
while len(U) > 1 and dir(U[-2], U[-1], p) <= 0: U.pop() |
118 |
|
while len(L) > 1 and dir(L[-2], L[-1], p) >= 0: L.pop() |
119 |
|
U.append(p) |
120 |
|
L.append(p) |
121 |
|
|
122 |
|
#print "L=", [ (int(100*a),int(100*b)) for (a,b) in L ] |
123 |
|
#print "U=", [ (int(100*a),int(100*b)) for (a,b) in U ] |
124 |
|
|
125 |
|
U.reverse() |
126 |
|
return U + L[1:-1] |
127 |
|
|