コード例 #1
0
 def find_tangent_points(self, coord):
     #TODO can be convex hull instead of all coords
     tan_coords = []
     for c in self.coords:
         vec_to_c = coord.vec_to_coord(c)
         test_coord1 = c.coord_of_vec(Vector.Polar(0.001, vec_to_c.heading))
         test_coord2 = c.coord_of_vec(Vector.Polar(-0.001, vec_to_c.heading))
         if self.contains(test_coord1) or self.contains(test_coord2):
             continue
         tan_coords.append(c)
     return tan_coords
コード例 #2
0
    def buffer(self, dist):
            new_coords = []
            if ccw(self.coords):
                is_ccw = True
            else:
                is_ccw = False

            for i in range(len(self.coords)):
                j = (i+1) % len(self.coords)
                k = (i+2) % len(self.coords)

                vec1 = self.coords[i].vec_to_coord(self.coords[j])
                vec2 = self.coords[j].vec_to_coord(self.coords[k])

                if is_ccw:
                    psi = radians(90)
                else:
                    psi = -radians(90)

                perp_vec1 = Vector.Polar(dist, vec1.heading+psi)
                perp_vec2 = Vector.Polar(dist, vec2.heading+psi)

                # push walls out to make two lines
                c1 = self.coords[i].coord_of_vec(perp_vec1)
                c2 = self.coords[j].coord_of_vec(perp_vec1)
                c3 = self.coords[j].coord_of_vec(perp_vec2)
                c4 = self.coords[k].coord_of_vec(perp_vec2)

                # use coordinate of where those lines intersect TODO will need to change this
                x1, y1 = [0, 0]
                x2, y2 = c1.vec_to_coord(c2)._to_rect()
                x3, y3 = c1.vec_to_coord(c3)._to_rect()
                x4, y4 = c1.vec_to_coord(c4)._to_rect()

                px, py = find_intersection_point([x1, y1], [x2,y2], [x3,y3], [x4,y4])

                vec_to_intersection = Vector.XY(px, py)
                new_coord = c1.coord_of_vec(vec_to_intersection)
                colors = ['purple', 'orange', 'black', 'blue']
                #new_coords.append(new_coord)
                new_coords.append(c1)
                new_coords.append(c2)

            new_poly = Polygon(new_coords)
            return new_poly