3
from definitions import *
7
def __init__(self,x=0,z=0,size=16,depth= 4,top = None,left= None,right= None,bottom= None):
8
""" depth is the depth of the quadtree """
10
self.x,self.z,self.size = x,z,size
14
self.leftLine = Line(point = Point(x,0,z),vector = Vector(0,0,1))
18
self.topLine = Line(point = Point(x,0,z),vector = Vector(1,0,0))
22
self.rightLine = Line(point = Point(x+size,0,z+size),vector = Vector(0,0,1))
24
self.rightLine = right
26
self.bottomLine = Line(point = Point(x+size,0,z+size),vector = Vector(1,0,0))
28
self.bottomLine = bottom
33
x,z,size = self.x,self.z,self.size
35
# quad number 1 (top left) : top and left lines are the same as for the parent
36
self.sons.append(QuadTree(x=x,z=z,size=size/2.0,depth=self.depth - 1,top=self.topLine,left = self.leftLine))
37
# quad number 2 (top right) : top and right lines are the same as for the parent
38
self.sons.append(QuadTree(x=x+size/2.0,z=z,size=size/2.0,depth=self.depth - 1,top=self.topLine,right=self.rightLine))
39
# quad number 3 (bottom left) : bottom and left lines are the same as for the parent
40
self.sons.append(QuadTree(x=x,z=z+size/2.0,size=size/2.0,depth=self.depth - 1,bottom = self.bottomLine,left = self.leftLine))
41
# quad number 4 (bottom right) : bottom and right lines are the same as for the parent
42
self.sons.append(QuadTree(x=x+size/2.0,z=z+size/2.0,size=size/2.0,depth=self.depth - 1,right = self.rightLine,bottom = self.bottomLine))
44
def printNodesCoordinates(self):
45
for node in self.sons :
46
print node.depth,node.x,node.z
47
node.printNodesCoordinates()
49
def intersect(self,line,depth):
52
def testQuadTreeLines():
54
print c.sons[0].sons[3].sons[2].x , c.sons[0].sons[3].sons[2].z
55
l = Line(A = Point(6,0,4), B = Point(2,0,12))
56
p,t = l.intersect(c.sons[0].sons[3].sons[2].bottomLine)