示例#1
0
文件: main.py 项目: annell/Survive
N = 5000
coords = np.random.randn(N, 2) * height / 3 + (width / 2, height / 2)
points = [Point(*coord) for coord in coords]

domain = Rect(width / 2, height / 2, width, height)
qtree = QuadTree(domain, 3)
for point in points:
    qtree.insert(point)

print('Number of points in the domain =', len(qtree))

fig = plt.figure(figsize=(700 / DPI, 500 / DPI), dpi=DPI)
ax = plt.subplot()
ax.set_xlim(0, width)
ax.set_ylim(0, height)
qtree.draw(ax)

ax.scatter([p.x for p in points], [p.y for p in points], s=4)
ax.set_xticks([])
ax.set_yticks([])

region = Rect(140, 190, 150, 150)
found_points = []
qtree.query(region, found_points)
print('Number of found points =', len(found_points))

ax.scatter([p.x for p in found_points], [p.y for p in found_points],
           facecolors='none',
           edgecolors='r',
           s=32)
import matplotlib.pyplot as plt
import numpy as np
import random

from quadtree import Rectangle, QuadTree, Point

width = 500
height = 500

no_of_points = 300

boundary = Rectangle(0, 0, width, height)

qd = QuadTree(boundary)

for i in range(0, no_of_points):
    x = random.randint(0, width + 1)
    y = random.randint(0, height + 1)
    point = Point(x, y)
    qd.insert(point)

b = []
qd.getAllBoundaries(boundaries=b)
print(b)
qd.draw(plt)
plt.show()