public
Created

  • Download Gist
WTF??
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#!/usr/bin/env python
from __future__ import division
from collections import namedtuple
Coordinate = namedtuple("Coordinate", ["X", "Y", "Z"])
def elementWiseAdd(coord1, coord2): return Coordinate(coord1[0]+coord2[0], coord1[1]+coord2[1], coord1[2]+coord2[2])
def elementWiseSub(coord1, coord2): return Coordinate(coord1[0]-coord2[0], coord1[1]-coord2[1], coord1[2]-coord2[2])
def elementWiseDiv(coord, scale): return Coordinate(coord[0]/scale, coord[1]/scale, coord[2]/scale)
Coordinate.__add__ = elementWiseAdd
Coordinate.__sub__ = elementWiseSub
Coordinate.__div__ = elementWiseDiv
 
class BoundingBox(object):
def __init__(self, boundingStartPoint, boundingEndPoint, resolution):
self.resolution = resolution
self.startPoint = boundingStartPoint
self.endPoint = boundingEndPoint
dx = boundingEndPoint.X - boundingStartPoint.X
dy = boundingEndPoint.Y - boundingStartPoint.Y
dz = boundingEndPoint.Z - boundingStartPoint.Z
stepsX = int(abs(dx/resolution) + 1)
stepsY = int(abs(dy/resolution) + 1)
stepsZ = int(abs(dz/resolution) + 1)
self.visitedTable = [[[False] * stepsZ] * stepsY] * stepsX
 
def __coordToIndices(self, coordinate):
delta = coordinate - self.startPoint
import ipdb; ipdb.set_trace()
stepCount = delta + delta
stepCount = delta/self.resolution
#Seems silly but we're not returning a Coordinate so I'm "un-typing" it
return (stepCount[0], stepCount[1], stepCount[2])
 
def haveVisited(self,coordinate):
ind = self.__coordToIndices(coordinate)
return self.visitedTable[ind[0]][ind[1]][ind[2]]
 
if __name__ == "__main__":
foo = BoundingBox(Coordinate(0,0,0), Coordinate(1,1,0.5), 0.5)
print foo.haveVisited(Coordinate(0,1,0))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.