aboutsummaryrefslogtreecommitdiff
path: root/util/Geo.py
diff options
context:
space:
mode:
authorGravatar rcoh <rcoh@mit.edu>2011-01-27 16:50:59 -0500
committerGravatar rcoh <rcoh@mit.edu>2011-01-27 16:50:59 -0500
commit5fb3ea060025241105dc8e9a174513c112f9a133 (patch)
treee98b1b3eab0b05b0e518b08cbab086d224fd9250 /util/Geo.py
parent5d29906fff79bc6e4ba83be7028e1380a0014d21 (diff)
A metric $#%$-ton of changes. Added doc-strings to EVERYTHING. Phew. Fixed a massive bug that
increases performance in by up to a factor of 60. A bunch of new behaviors for the class.
Diffstat (limited to 'util/Geo.py')
-rw-r--r--util/Geo.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/util/Geo.py b/util/Geo.py
index be3e93e..05ea9fe 100644
--- a/util/Geo.py
+++ b/util/Geo.py
@@ -4,20 +4,25 @@ from bisect import *
import random
def pointWithinBoundingBox(point, bb): #this could be in 4 lines, but I'm lazy.
return sum([(point[i % 2] <= bb[i]) == (i>1) for i in range(4)]) == 4
+
def addLocations(l1,l2):
return tuple([l1[i]+l2[i] for i in range(len(l1))])
+
def gaussian(x,height,center,width):
a=height
b=center
c=width
return a*math.exp(-((x-b)**2)/(2*c**2))
+
def dist(l1, l2):
- return math.sqrt((l1[0]-l2[0])**2+(l1[1]-l2[1])**2)
- #return math.sqrt(sum([(l1[i]-l2[i])**2 for i in range(len(l1))]))
+ return math.sqrt((l1[0]-l2[0])**2+(l1[1]-l2[1])**2) #For speed
+
def randomLoc(boundingBox): #TODO: make less shitty
loc = []
loc.append(random.randint(0, boundingBox[0]))
loc.append(random.randint(0, boundingBox[1]))
return tuple(loc)
+
def approxexp(x):
+ """Approximates exp with a 3 term Taylor Series."""
return 1+x+x**2/2+x**3/6