Пример #1
0
    def draw_sensors(self, maze_walls, beacons):
        landmarks = []
        for beacon in beacons:
            collide = False
            point = Point(beacon[0])
            line = LineString([((self.position[0]), (self.position[1])), beacon[0]])
            distance = point.hausdorff_distance(line)
            if distance < self.max_distance_sensor:
                # TODO collision check
                for wall in maze_walls:
                    line_wall = LineString([(wall[0][0], wall[0][1]),
                                            (wall[1][0], wall[1][1])])
                    if line.intersects(line_wall):
                        if not point.intersects(line_wall):
                            collide = True

                if not collide:
                    pygame.draw.line(self.screen, data.COLOR_SENSOR_LINE,
                                     (self.round(self.position[0]), (self.round_Y(self.position[1]))),
                                     (self.round_point(beacon[0])), 2)
                    landmarks.append([line, distance, beacon])
        return landmarks
Пример #2
0
    def test_hausdorff_distance(self):
        point = Point(1, 1)
        line = LineString([(2, 0), (2, 4), (3, 4)])

        distance = point.hausdorff_distance(line)
        self.assertEqual(distance, point.distance(Point(3, 4)))
Пример #3
0
        self.__geo_interface__ = d


thing = GeoThing({"type": "Point", "coordinates": (0.0, 0.0)})
m = mapping(thing)
print("", m['type'])
print(m['coordinates'])

print("---------------LineStriing-----------------")
line = LineString([(2, 0), (2, 2), (0, 2)])
# area 面积
print(line.area)
# length 长度
print(line.length)
# hausdorff_distance  豪斯多夫 距离
print(point.hausdorff_distance(line))
print(point.distance(Point(2, 2)))
print(list(line.coords))
print(line.coords[0])
print(line.coords[1:])
for x, y in line.coords:
    print("x = {},y = {} ".format(x, y))
# == 和 equals 的区别
a = LineString([(0, 0), (1, 1)])
b = LineString([(0, 0), (0.5, 0.5), (1, 1)])
c = LineString([(0, 0), (0, 0), (1, 1)])
print(a.equals(b))
print(a == b)
print(b.equals(c))
print(b == c)
# contains 包含于, within 被包含于