示例#1
0
            def recursive_discard_edge(ray, other_point, base_point, side):
                #want to delete left remaining line
                for candidate in ray.connected:
                    if candidate.avail == True and candidate not in ray_list:
                        next_base_point = None
                        next_other_point = None
                        #catch base point
                        if (candidate.p1 is base_point
                                or candidate.p2 is base_point):
                            if candidate.p1 is base_point:
                                next_base_point = candidate.p2
                                next_other_point = candidate.p1
                            else:
                                next_base_point = candidate.p1
                                next_other_point = candidate.p2

                            if side == 'right':
                                if ConvexHull.cross(base_point,
                                                    next_base_point,
                                                    other_point) > 0:
                                    candidate.avail = False
                                    recursive_discard_edge(
                                        candidate, next_other_point,
                                        next_base_point, 'right')
                            elif side == 'left':
                                if ConvexHull.cross(base_point,
                                                    next_base_point,
                                                    other_point) < 0:
                                    candidate.avail = False
                                    recursive_discard_edge(
                                        candidate, next_other_point,
                                        next_base_point, 'left')
示例#2
0
            def recursive_discard_edge(ray,other_point,base_point,side):
                #want to delete left remaining line
                for candidate in ray.connected:
                    if candidate.avail == True and candidate not in ray_list:
                        next_base_point = None
                        next_other_point = None
                        #catch base point
                        if(candidate.p1 is base_point or candidate.p2 is base_point):
                            if candidate.p1 is base_point:
                                next_base_point = candidate.p2
                                next_other_point = candidate.p1
                            else:
                                next_base_point = candidate.p1
                                next_other_point = candidate.p2

                            if side == 'right':
                                if ConvexHull.cross(base_point,next_base_point,other_point) > 0:
                                    candidate.avail = False
                                    recursive_discard_edge(candidate,next_other_point,next_base_point,'right')
                            elif side == 'left':
                                if ConvexHull.cross(base_point,next_base_point,other_point) < 0:
                                    candidate.avail = False
                                    recursive_discard_edge(candidate,next_other_point,next_base_point,'left')
示例#3
0
 def islower_tangent(pl, pr, pos):
     if pos == 'left':
         return ConvexHull.cross(pr, pl, pl.cw) >= 0
     else:
         return ConvexHull.cross(pl, pr, pr.ccw) <= 0
示例#4
0
 def isupper_tangent(pl, pr, pos):
     if pos == 'left':
         #because y is reverse in canvas,so we need to reverse the clockwise/clock,debug this is so diffcult...
         return ConvexHull.cross(pr, pl, pl.ccw) <= 0
     else:
         return ConvexHull.cross(pl, pr, pr.cw) >= 0
示例#5
0
 def find_convex(self):
     return ConvexHull(self).Andrew_monotone_chain(self.range_points)
示例#6
0
        def discard_edges(ray, circumcenter, side, SG_bisector):
            def recursive_discard_edge(ray, other_point, base_point, side):
                #want to delete left remaining line
                for candidate in ray.connected:
                    if candidate.avail == True and candidate not in ray_list:
                        next_base_point = None
                        next_other_point = None
                        #catch base point
                        if (candidate.p1 is base_point
                                or candidate.p2 is base_point):
                            if candidate.p1 is base_point:
                                next_base_point = candidate.p2
                                next_other_point = candidate.p1
                            else:
                                next_base_point = candidate.p1
                                next_other_point = candidate.p2

                            if side == 'right':
                                if ConvexHull.cross(base_point,
                                                    next_base_point,
                                                    other_point) > 0:
                                    candidate.avail = False
                                    recursive_discard_edge(
                                        candidate, next_other_point,
                                        next_base_point, 'right')
                            elif side == 'left':
                                if ConvexHull.cross(base_point,
                                                    next_base_point,
                                                    other_point) < 0:
                                    candidate.avail = False
                                    recursive_discard_edge(
                                        candidate, next_other_point,
                                        next_base_point, 'left')

            if side == 'right':
                #clear the edges extend to the left of HP
                #Line(hole,ray.p1) or Line(hole,ray.p2) must cw to Line(hole,bisector.p1)
                if ConvexHull.cross(circumcenter, ray.p1, SG_bisector.p1) > 0:
                    #this means p1 is left to circumcenter,so replace p1 with circumcenter
                    if ray.p1.iscircumcenter == True:
                        recursive_discard_edge(ray, circumcenter, ray.p1,
                                               'right')
                    ray.p1 = circumcenter
                else:
                    if ray.p2.iscircumcenter == True:
                        recursive_discard_edge(ray, circumcenter, ray.p2,
                                               'right')
                    ray.p2 = circumcenter
            elif side == "left":
                #clear the edges extend to the right of HP
                #Line(hole,ray.p1) or Line(hole,ray.p2) must ccw to Line(hole,bisector.p1)
                if ConvexHull.cross(circumcenter, ray.p1, SG_bisector.p1) < 0:
                    #this means p1 is right to circumcenter,so replace p1 with circumcenter
                    if ray.p1.iscircumcenter == True:
                        recursive_discard_edge(ray, circumcenter, ray.p1,
                                               'left')
                    ray.p1 = circumcenter
                else:

                    if ray.p2.iscircumcenter == True:
                        recursive_discard_edge(ray, circumcenter, ray.p2,
                                               'left')
                    ray.p2 = circumcenter
            else:
                #clear both side
                #clear the edges extend to the right of HP
                #Line(hole,ray.p1) or Line(hole,ray.p2) must ccw to Line(hole,bisector.p1)
                if ConvexHull.cross(circumcenter, ray[0].p1,
                                    SG_bisector.p1) < 0:
                    #this means p1 is right to circumcenter,so replace p1 with circumcenter
                    if ray[0].p1.iscircumcenter == True:
                        recursive_discard_edge(ray[0], circumcenter, ray[0].p1,
                                               'left')
                    ray[0].p1 = circumcenter
                else:
                    if ray[0].p2.iscircumcenter == True:
                        recursive_discard_edge(ray[0], circumcenter, ray[0].p2,
                                               'left')
                    ray[0].p2 = circumcenter

                #clear the edges extend to the left of HP
                if ConvexHull.cross(circumcenter, ray[1].p1,
                                    SG_bisector.p1) > 0:
                    #this means p1 is left to circumcenter,so replace p1 with circumcenter
                    if ray[1].p1.iscircumcenter == True:
                        recursive_discard_edge(ray[1], circumcenter, ray[1].p1,
                                               'right')
                    ray[1].p1 = circumcenter
                else:
                    if ray[1].p2.iscircumcenter == True:
                        recursive_discard_edge(ray[1], circumcenter, ray[1].p2,
                                               'right')
                    ray[1].p2 = circumcenter
示例#7
0
 def islower_tangent(pl,pr,pos):
     if pos == 'left':
         return ConvexHull.cross(pr,pl,pl.cw) >= 0
     else:
         return ConvexHull.cross(pl,pr,pr.ccw) <= 0
示例#8
0
 def isupper_tangent(pl,pr,pos):
     if pos == 'left':
         #because y is reverse in canvas,so we need to reverse the clockwise/clock,debug this is so diffcult...
         return ConvexHull.cross(pr,pl,pl.ccw) <= 0
     else:
         return ConvexHull.cross(pl,pr,pr.cw) >= 0
示例#9
0
        def discard_edges(ray,circumcenter,side,SG_bisector):

            def recursive_discard_edge(ray,other_point,base_point,side):
                #want to delete left remaining line
                for candidate in ray.connected:
                    if candidate.avail == True and candidate not in ray_list:
                        next_base_point = None
                        next_other_point = None
                        #catch base point
                        if(candidate.p1 is base_point or candidate.p2 is base_point):
                            if candidate.p1 is base_point:
                                next_base_point = candidate.p2
                                next_other_point = candidate.p1
                            else:
                                next_base_point = candidate.p1
                                next_other_point = candidate.p2

                            if side == 'right':
                                if ConvexHull.cross(base_point,next_base_point,other_point) > 0:
                                    candidate.avail = False
                                    recursive_discard_edge(candidate,next_other_point,next_base_point,'right')
                            elif side == 'left':
                                if ConvexHull.cross(base_point,next_base_point,other_point) < 0:
                                    candidate.avail = False
                                    recursive_discard_edge(candidate,next_other_point,next_base_point,'left')

            if side == 'right':
                #clear the edges extend to the left of HP
                #Line(hole,ray.p1) or Line(hole,ray.p2) must cw to Line(hole,bisector.p1)
                if ConvexHull.cross(circumcenter,ray.p1,SG_bisector.p1)>0:
                    #this means p1 is left to circumcenter,so replace p1 with circumcenter
                    if ray.p1.iscircumcenter == True:
                        recursive_discard_edge(ray,circumcenter,ray.p1,'right')
                    ray.p1 = circumcenter
                else:
                    if ray.p2.iscircumcenter == True:
                        recursive_discard_edge(ray,circumcenter,ray.p2,'right')
                    ray.p2 = circumcenter
            elif side == "left":
                #clear the edges extend to the right of HP
                #Line(hole,ray.p1) or Line(hole,ray.p2) must ccw to Line(hole,bisector.p1)
                if ConvexHull.cross(circumcenter,ray.p1,SG_bisector.p1)<0:
                    #this means p1 is right to circumcenter,so replace p1 with circumcenter
                    if ray.p1.iscircumcenter == True:
                        recursive_discard_edge(ray,circumcenter,ray.p1,'left')
                    ray.p1 = circumcenter
                else:

                    if ray.p2.iscircumcenter == True:
                        recursive_discard_edge(ray,circumcenter,ray.p2,'left')
                    ray.p2 = circumcenter
            else:
                #clear both side
                #clear the edges extend to the right of HP
                #Line(hole,ray.p1) or Line(hole,ray.p2) must ccw to Line(hole,bisector.p1)
                if ConvexHull.cross(circumcenter,ray[0].p1,SG_bisector.p1)<0:
                    #this means p1 is right to circumcenter,so replace p1 with circumcenter
                    if ray[0].p1.iscircumcenter == True:
                        recursive_discard_edge(ray[0],circumcenter,ray[0].p1,'left')
                    ray[0].p1 = circumcenter
                else:
                    if ray[0].p2.iscircumcenter == True:
                        recursive_discard_edge(ray[0],circumcenter,ray[0].p2,'left')
                    ray[0].p2 = circumcenter

                #clear the edges extend to the left of HP
                if ConvexHull.cross(circumcenter,ray[1].p1,SG_bisector.p1)>0:
                    #this means p1 is left to circumcenter,so replace p1 with circumcenter
                    if ray[1].p1.iscircumcenter == True:
                        recursive_discard_edge(ray[1],circumcenter,ray[1].p1,'right')
                    ray[1].p1 = circumcenter
                else:
                    if ray[1].p2.iscircumcenter == True:
                        recursive_discard_edge(ray[1],circumcenter,ray[1].p2,'right')
                    ray[1].p2 = circumcenter