Beispiel #1
0
    def complexPoly(self, vertices, dynamic=True, density=1.0, restitution=0.16, friction=0.5):
        # 1. Step: Reduce
        # 2. Step: See if start and end are close, if so then close the polygon
        # 3. Step: Detect if convex or concave
        # 4. Step: Start self.convexPoly or self.concavePoly
        vertices, is_convex = tools_poly.reduce_poly_by_angle(vertices)            
        #print "->", is_convex

        # If start and endpoints are close to each other, close polygon
        x1, y1 = vertices[0]
        x2, y2 = vertices[-1]
        dx = x2 - x1
        dy = y2 - y1
        l = sqrt((dx*dx)+(dy*dy))

        if l < 50:
            vertices[-1] = vertices[0]
        else:
            # Never convex if open (we decide so :)
            is_convex = False

        if tools_poly.is_line(vertices):
            # Lines shall be drawn by self.concavePoly(...)
            print "is line"
            is_convex = False
                    
        if is_convex:
            print "convex"
            return self.convexPoly(vertices, dynamic, density, restitution, friction), vertices
        else:
            print "concave"
            return self.concavePoly(vertices, dynamic, density, restitution, friction), vertices        
    def complexPoly(
            self,
            vertices,
            dynamic=True,
            density=1.0,
            restitution=0.16,
            friction=0.5):
        # 1. Step: Reduce
        # 2. Step: See if start and end are close, if so then close the polygon
        # 3. Step: Detect if convex or concave
        # 4. Step: Start self.convexPoly or self.concavePoly
        vertices, is_convex = tools_poly.reduce_poly_by_angle(vertices)
        # print "->", is_convex

        # If start and endpoints are close to each other, close polygon
        x1, y1 = vertices[0]
        x2, y2 = vertices[-1]
        dx = x2 - x1
        dy = y2 - y1
        l = sqrt((dx * dx) + (dy * dy))

        if l < 50:
            vertices[-1] = vertices[0]
        else:
            # Never convex if open (we decide so :)
            is_convex = False

        if tools_poly.is_line(vertices):
            # Lines shall be drawn by self.concavePoly(...)
            print "is line"
            is_convex = False

        if is_convex:
            print "convex"
            return self.convexPoly(
                vertices, dynamic, density, restitution, friction), vertices
        else:
            print "concave"
            return self.concavePoly(
                vertices, dynamic, density, restitution, friction), vertices