Package SmootLight :: Package util :: Module Geo
[hide private]
[frames] | no frames]

Source Code for Module SmootLight.util.Geo

 1  #Geometry code 
 2  import math 
 3  from bisect import * 
 4  import random 
5 -def pointWithinBoundingBox(point, bb):
6 """Returns whether or not a point (x,y) is within a bounding box (xmin, ymin, xmax, ymax)""" 7 return all([(point[i % 2] <= bb[i]) == (i>1) for i in range(4)]) 8
9 -def addLocations(l1,l2):
10 return tuple([l1[i]+l2[i] for i in range(len(l1))])
11
12 -def gaussian(x,height,center,width):
13 a=height 14 b=center 15 c=width 16 return a*math.exp(-((x-b)**2)/(2*c**2))
17
18 -def dist(l1, l2):
19 return math.sqrt((l1[0]-l2[0])**2+(l1[1]-l2[1])**2) #For speed
20
21 -def randomLoc(boundingBox): #TODO: make less shitty
22 loc = [] 23 loc.append(random.randint(0, boundingBox[0])) 24 loc.append(random.randint(0, boundingBox[1])) 25 return tuple(loc) 26
27 -def approxexp(x):
28 """Approximates exp with a 3 term Taylor Series.""" 29 return 1+x+x**2/2+x**3/6
30
31 -def windtrail(x,y,height,center,width):
32 a=height 33 b=center 34 c=width 35 return a*((math.exp(-((x-b))/(c)))**2)*(math.exp(-((y))/(0.2*c)))**2
36
37 -class Location(object):
38 - def __init__(self,x=0,y=0):
39 self.x = x 40 self.y = y
41 - def __add__(self, b):
42 return Location(self.x+b.x, self.y+b.y)
43