Exemplo n.º 1
0
def Dubins_msg(UAV, target, R0):
    v = UAV.v 
    phi0 = UAV.phi
    UAV_p = Point(UAV.site)
    target_p = Point(target[0:2])

    c1 = Point(UAV_p.x + R0 * np.sin(phi0), UAV_p.y - R0 * np.cos(phi0))
    c2 = Point(UAV_p.x - R0 * np.sin(phi0), UAV_p.y + R0 * np.cos(phi0))
    len1 = c1.distance(target_p)
    len2 = c2.distance(target_p)
    center = c1

    if len2 > len1:
        center = c2

    center = Point(round(center.x.evalf(), 4), round(center.y.evalf(), 4))
    circle = Circle(center, R0)
    tangent_lines = Tangent_lines(circle, target_p)
    tangent_line1 = tangent_lines[0]  
    tangent_line1 = Line(tangent_line1.p2, tangent_line1.p1)
    tangent_point1 = tangent_line1.p1
    y = float((target_p.y - tangent_point1.y).evalf())
    x = float((target_p.x - tangent_point1.x).evalf())
    tangent_angle1 = np.arctan2(y, x)

    tangent_line2 = tangent_lines[1]
    tangent_line2 = Line(tangent_line2.p2, tangent_line2.p1)
    tangent_point2 = tangent_line2.p1
    y = float((target_p.y - tangent_point2.y).evalf())
    x = float((target_p.x - tangent_point2.x).evalf())
    tangent_angle2 = np.arctan2(y, x)

    vec1 = [UAV_p.x - center.x, UAV_p.y - center.y]
    vec2 = [np.cos(phi0), np.sin(phi0)]
    direction = np.sign(vec1[0] * vec2[1] - vec1[1] * vec2[0])
    sin1 = float(tangent_point1.distance(UAV_p).evalf()) / (2 * R0)
    angle1 = 2 * np.arcsin(sin1)
    sin2 = float(tangent_point2.distance(UAV_p).evalf()) / (2 * R0)
    angle2 = 2 * np.arcsin(sin2)

    tangent_point = []
    radian = 0

    if abs(modf(abs(direction * angle1 + phi0 - tangent_angle1) / (2 * np.pi))[0] - 0.5) > 0.5 - deviation:
        tangent_point = tangent_point1
        radian = angle1
    elif abs(modf(abs(direction * (2 * np.pi - angle1) + phi0 - tangent_angle1) / (2 * np.pi))[
                 0] - 0.5) > 0.5 - deviation:
        tangent_point = tangent_point1
        radian = 2 * np.pi - angle1
    elif abs(modf(abs(direction * angle2 + phi0 - tangent_angle2) / (2 * np.pi))[0] - 0.5) > 0.5 - deviation:
        tangent_point = tangent_point2
        radian = angle2
    elif abs(modf(abs(direction * (2 * np.pi - angle2) + phi0 - tangent_angle2) / (2 * np.pi))[
                 0] - 0.5) > 0.5 - deviation:
        tangent_point = tangent_point2
        radian = 2 * np.pi - angle2

    return direction, radian, (float(tangent_point.x.evalf()), float(tangent_point.y.evalf())), (
        float(center.x.evalf()), float(center.y.evalf()))
Exemplo n.º 2
0
    def distance(self, other):
        """The Euclidean distance between self and another GeometricEntity.

        Returns
        =======

        distance : number or symbolic expression.

        Raises
        ======
        AttributeError : if other is a GeometricEntity for which
                         distance is not defined.
        TypeError : if other is not recognized as a GeometricEntity.

        See Also
        ========

        sympy.geometry.line.Segment.length
        sympy.geometry.point.Point.taxicab_distance

        Examples
        ========

        >>> from sympy.geometry import Point, Line
        >>> p1, p2 = Point(1, 1), Point(4, 5)
        >>> l = Line((3, 1), (2, 2))
        >>> p1.distance(p2)
        5
        >>> p1.distance(l)
        sqrt(2)

        The computed distance may be symbolic, too:

        >>> from sympy.abc import x, y
        >>> p3 = Point(x, y)
        >>> p3.distance((0, 0))
        sqrt(x**2 + y**2)

        """
        if not isinstance(other, GeometryEntity):
            try:
                other = Point(other, dim=self.ambient_dimension)
            except TypeError:
                raise TypeError("not recognized as a GeometricEntity: %s" %
                                type(other))
        if isinstance(other, Point):
            s, p = Point._normalize_dimension(self, Point(other))
            return sqrt(Add(*((a - b)**2 for a, b in zip(s, p))))
        try:
            return other.distance(self)
        except AttributeError:
            raise AttributeError(
                "distance between Point and %s is not defined" % type(other))
Exemplo n.º 3
0
Arquivo: point.py Projeto: cklb/sympy
    def distance(self, other):
        """The Euclidean distance between self and another GeometricEntity.

        Returns
        =======

        distance : number or symbolic expression.

        Raises
        ======
        AttributeError : if other is a GeometricEntity for which
                         distance is not defined.
        TypeError : if other is not recognized as a GeometricEntity.

        See Also
        ========

        sympy.geometry.line.Segment.length
        sympy.geometry.point.Point.taxicab_distance

        Examples
        ========

        >>> from sympy.geometry import Point, Line
        >>> p1, p2 = Point(1, 1), Point(4, 5)
        >>> l = Line((3, 1), (2, 2))
        >>> p1.distance(p2)
        5
        >>> p1.distance(l)
        sqrt(2)

        The computed distance may be symbolic, too:

        >>> from sympy.abc import x, y
        >>> p3 = Point(x, y)
        >>> p3.distance((0, 0))
        sqrt(x**2 + y**2)

        """
        if not isinstance(other , GeometryEntity) :
            try :
                other = Point(other, dim=self.ambient_dimension)
            except TypeError :
                raise TypeError("not recognized as a GeometricEntity: %s" % type(other))
        if isinstance(other , Point) :
            s, p = Point._normalize_dimension(self, Point(other))
            return sqrt(Add(*((a - b)**2 for a, b in zip(s, p))))
        try :
            return other.distance(self)
        except AttributeError :
            raise AttributeError("distance between Point and %s is not defined" % type(other))
    def Angle(self):
        yAxis = Line(Point(0, 1), Point(0, 0))
        point1 = Point(self.Box[1][0], self.Box[1][1])
        point2 = Point(self.Box[0][0], self.Box[0][1])
        point3 = Point(self.Box[2][0], self.Box[2][1])

        if point1.distance(point2) > point1.distance(point3):
            longerLine = Line(point1, point2)
        else:
            longerLine = Line(point1, point3)

        angle = int(math.degrees(yAxis.angle_between(longerLine)))

        if (int(angle) > 90):
            if angle - 180 + 80 >= 0:
                return angle - 180 + 80
            else:
                return 0
        else:
            if angle + 80 >= 0:
                return angle + 80
            else:
                return 0
Exemplo n.º 5
0
def Dubins_msg(UAV, target, R0):
    # 单架无人机到达目标点所需时间
    #  这里的UAV和target是无人机和目标对象
    v = UAV.v  # 飞机速度
    phi0 = UAV.phi  # 转化为弧度,[0,2pi]

    UAV_p = Point(UAV.site)
    target_p = Point(target[0:2])

    # 以上为所有已知信息

    # 1. 求两个圆心,判断出采用哪一个圆
    # 2. 求切线
    # 3. 确定用那一段弧长

    # 1.求两个圆心,判断出采用哪一个圆
    c1 = Point(UAV_p.x + R0 * np.sin(phi0), UAV_p.y - R0 * np.cos(phi0))
    c2 = Point(UAV_p.x - R0 * np.sin(phi0), UAV_p.y + R0 * np.cos(phi0))
    len1 = c1.distance(target_p)
    len2 = c2.distance(target_p)
    center = c1

    if len2 > len1:
        center = c2

    # 2. 求切线
    center = Point(round(center.x.evalf(), 4), round(center.y.evalf(), 4))
    circle = Circle(center, R0)
    # start=time.time()
    # tangent_lines = circle.tangent_lines(target_p)
    tangent_lines = Tangent_lines(circle, target_p)
    # end=time.time()
    # print(end-start)
    tangent_line1 = tangent_lines[0]  # 注意这里的切线方向是从target-> 切点
    tangent_line1 = Line(tangent_line1.p2, tangent_line1.p1)  # 改为从切点->target
    tangent_point1 = tangent_line1.p1  # 切点1
    y = float((target_p.y - tangent_point1.y).evalf())
    x = float((target_p.x - tangent_point1.x).evalf())
    tangent_angle1 = np.arctan2(y, x)  # arctan2(y,x) 向量(x,y)的角度[-pi,pi]

    tangent_line2 = tangent_lines[1]
    tangent_line2 = Line(tangent_line2.p2, tangent_line2.p1)  # 改为从切点->target
    tangent_point2 = tangent_line2.p1  # 切点2
    y = float((target_p.y - tangent_point2.y).evalf())
    x = float((target_p.x - tangent_point2.x).evalf())
    tangent_angle2 = np.arctan2(y, x)  # arctan2(y,x) 向量(x,y)的角度[-pi,pi]

    # 3. 确定用哪一段弧长
    # a. 确定用顺时针还是逆时针
    vec1 = [UAV_p.x - center.x, UAV_p.y - center.y]
    vec2 = [np.cos(phi0), np.sin(phi0)]
    direction = np.sign(vec1[0] * vec2[1] - vec1[1] * vec2[0])  # 1 表示逆时针 -1 表示顺时针
    # b. 判断是哪一个切点,哪一段弧
    sin1 = float(tangent_point1.distance(UAV_p).evalf()) / (2 * R0)
    angle1 = 2 * np.arcsin(sin1)  # 无人机位置与切点之间的弧度[0,pi] 小弧
    sin2 = float(tangent_point2.distance(UAV_p).evalf()) / (2 * R0)
    angle2 = 2 * np.arcsin(sin2)

    tangent_point = []
    hudu = 0

    # 判断式的意思  角度要在误差范围内相隔2kpi,使用modf(abs 把值控制在0-1之内,误差范围内靠近1,靠近0 都ok  用于0.5之间的距离来判断
    if abs(modf(abs(direction * angle1 + phi0 - tangent_angle1) / (2 * np.pi))[0] - 0.5) > 0.5 - deviation:
        tangent_point = tangent_point1
        hudu = angle1
    # modf 返回浮点数的小数部分和整数部分modf(1.23) return [0.23,1]
    elif abs(modf(abs(direction * (2 * np.pi - angle1) + phi0 - tangent_angle1) / (2 * np.pi))[
                 0] - 0.5) > 0.5 - deviation:
        tangent_point = tangent_point1
        hudu = 2 * np.pi - angle1
    elif abs(modf(abs(direction * angle2 + phi0 - tangent_angle2) / (2 * np.pi))[0] - 0.5) > 0.5 - deviation:
        tangent_point = tangent_point2
        hudu = angle2
    elif abs(modf(abs(direction * (2 * np.pi - angle2) + phi0 - tangent_angle2) / (2 * np.pi))[
                 0] - 0.5) > 0.5 - deviation:
        tangent_point = tangent_point2
        hudu = 2 * np.pi - angle2

    # 返回 旋转方向 弧度 切点坐标 圆心坐标
    return direction, hudu, (float(tangent_point.x.evalf()), float(tangent_point.y.evalf())), (
        float(center.x.evalf()), float(center.y.evalf()))
Exemplo n.º 6
0
 def __abs__(self):
     """Returns the distance between this point and the origin."""
     origin = Point([0] * len(self.args))
     return Point.distance(origin, self)
Exemplo n.º 7
0
                gray = rotateImage(gray, angle, tuple(shape[33]))
                # gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
                rects = detector(gray, 1)

                # loop over the face detections
                for (k, rect) in enumerate(rects):
                    shape = predictor(gray, rect)
                    shape = face_utils.shape_to_np(shape)
                    eye = Point(shape[37])
                    eyebrow = Point(shape[19])
                    left = Point(min(shape, key=itemgetter(0)))
                    top = Point(min(shape, key=itemgetter(1)))
                    right = Point(max(shape, key=itemgetter(0)))
                    bottom = Point(max(shape, key=itemgetter(1)))

                    gray = gray[int(top.y - eye.distance(eyebrow) / 2):int(top.y + top.distance(bottom)),
                           int(left.x):int(left.x + left.distance(right))]

                    # ujednacavanje histograma
                    clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
                    gray = clahe.apply(gray)
                    # gray = cv2.bilateralFilter(gray, 9, 75, 75)

                    ratio = 300.0 / gray.shape[1]
                    dimensions = (300, int(gray.shape[0] * ratio))

                    gray = cv2.resize(gray, dimensions, interpolation=cv2.INTER_AREA)
                    cv2.imwrite("Users/" + person + "/processed/" + faceImageFile, gray)

                    print("File: " + faceImageFile)
                    # faceImage = cv2.imread("Users/" + person + "/" + faceImageFile, 0)
Exemplo n.º 8
0
 def __abs__(self):
     """Returns the distance between this point and the origin."""
     origin = Point([0]*len(self.args))
     return Point.distance(origin, self)
Exemplo n.º 9
0
def biarc_avg(w0, p0, p1, t0, t1, r0=1., r1=1.):
    global IN_DEBUG

    DEBUG = 'IN_DEBUG' in globals()
    if DEBUG and IN_DEBUG:
        fig = plt.figure()
        #_, _, _ = create_input_log_spiral()

    numpy_io = False
    if isinstance(p0, np.ndarray):
        numpy_io = True
        p0 = Point(p0[0], p0[1], evaluate=False)
        p1 = Point(p1[0], p1[1], evaluate=False)
        t0 = Point(t0[0], t0[1], evaluate=False)
        t1 = Point(t1[0], t1[1], evaluate=False)

    t0 = Point(float(t0.unit.x), float(t0.unit.y), evaluate=False)
    t1 = Point(float(t1.unit.x), float(t1.unit.y), evaluate=False)
    p0p1_segm_vec = Line(p0, p1).direction.unit
    tangents_equal = t1.distance(t0) < 0.0001
    segm_tang_collinear = t1.distance(p0p1_segm_vec) < 0.0001 or \
                          t1.distance(-p0p1_segm_vec) < 0.0001
    if tangents_equal and segm_tang_collinear:
        res_pt = (1. - w0) * p0 + w0 * p1
        res_tg = Point(t0[0], t0[1]) if numpy_io else t0
    else:
        # --- try 2 ----------------------------------------------------------
        prevInDebg = IN_DEBUG
        jnc_cntr, jnc_radius = get_junction_circle(p0, p1, t0, t1)
        osc_seg0_start, osc_seg0_end = get_arc_seg(p0, t0, r0, jnc_cntr,
                                                   jnc_radius, p0, p1)
        osc_seg1_start, osc_seg1_end = get_arc_seg(p1, t1, r1, jnc_cntr,
                                                   jnc_radius, osc_seg0_start,
                                                   osc_seg0_end)
        target_arc = CircArc(osc_seg1_start, osc_seg1_end, jnc_cntr)
        target_len = w0 * target_arc.get_length()
        res_pt, res_tg = target_arc.eval_pt_tang(target_len)
        res_radius = jnc_radius  #target_arc.radius

        #oscul_cntr0 = get_osculating_center(p0, t0, r0, jnc_cntr)
        #oscul_cntr1 = get_osculating_center(p1, t1, r1, jnc_cntr)
        #c0_jnc_intr = get_circles_intersection(jnc_cntr, jnc_radius, oscul_cntr0, r0)
        #c1_jnc_intr = get_circles_intersection(jnc_cntr, jnc_radius, oscul_cntr1, r1)
        #IN_DEBUG = prevInDebg

        #jnc_pts_cands = c0_jnc_intr + c1_jnc_intr
        #if DEBUG and IN_DEBUG:
        #    for inx_pt in jnc_pts_cands:
        #        draw_point(inx_pt, "#A569BD")
        #    draw_circle(jnc_cntr, jnc_radius, "#76D7C4")
        #    draw_circle(oscul_cntr0, r0, "#85C1E9")
        #    draw_circle(oscul_cntr1, r1, "#85C1E9")

        #p0_ang_jnc_circ = get_angle(float(p0.x - jnc_cntr.x),
        #                           float(p0.y - jnc_cntr.y))
        #p1_ang_jnc_circ = get_angle(float(p1.x - jnc_cntr.x),
        #                           float(p1.y - jnc_cntr.y))
        #min_ang_jnc_circ = min(p0_ang_jnc_circ, p1_ang_jnc_circ)
        #max_ang_jnc_circ = max(p0_ang_jnc_circ, p1_ang_jnc_circ)
        #if (max_ang_jnc_circ - min_ang_jnc_circ) > np.pi:
        #    # we pass zero angle
        #    pass

        #jnc_pt_angles = [get_angle(float(inx_pt.x - jnc_cntr.x),
        #                           float(inx_pt.y - jnc_cntr.y))
        #                 for inx_pt in jnc_pts_cands]
        #for ang in jnc_pt_angles:
        #    if min_ang_jnc_circ <= ang <= max_ang_jnc_circ:
        # --- try 2 ----------------------------------------------------------

        # --- try 1 ----------------------------------------------------------
        #anchor_pt = get_anchor_pt(p0, p1, t0, t1, r0, r1)
        #left_biarc = get_secondary_biarc(p0, t0, anchor_pt, True)
        #rght_biarc = get_secondary_biarc(p1, t1, anchor_pt, False)
        #left_len = float(left_biarc.get_length())
        #rght_len = float(rght_biarc.get_length())
        #trgt_len = float(w0*(left_len + rght_len))
        #if np.abs(trgt_len - left_len) < 0.0001:
        #    res_pt = anchor_pt
        #    res_tg = left_biarc.eval_end_pt_tang(False)
        #else:
        #    if float(trgt_len) < float(left_len):
        #        trgt_biarc = left_biarc
        #    else:
        #        trgt_biarc = rght_biarc
        #        trgt_len -= left_len
        #    res_pt, res_tg = trgt_biarc.eval_pt_tang(trgt_len)
        # --------------------------------------------------------------------

    res_radius = (1. - w0) * r0 + w0 * r1

    DEBUG = 'IN_DEBUG' in globals()
    if DEBUG and IN_DEBUG:
        #left_biarc.draw(plt.gca(), "#FF99FF")
        #rght_biarc.draw(plt.gca(), "#7F00FF")
        rnr = mpt.Arrow(float(res_pt.x),
                        float(res_pt.y),
                        float(res_tg.x),
                        float(res_tg.y),
                        width=0.6,
                        fc="r",
                        ec='none')
        plt.gca().add_patch(rnr)
        crc = mpt.Circle([float(res_pt.x), float(res_pt.y)],
                         radius=float(0.4),
                         ec="r",
                         fill=False)
        plt.gca().add_patch(crc)

        plt.axis('equal')
        plt.xlim([-5, 20])
        plt.ylim([-15, 10])
        plt.show()

    if numpy_io:
        res_pt = np.array([float(res_pt.x), float(res_pt.y)])
        res_tg = np.array([float(res_tg.x), float(res_tg.y)])
        if np.linalg.norm(res_tg) < 0.0001:
            a = 5
        res_tg /= np.linalg.norm(res_tg)
    return res_pt, res_tg, res_radius
def circular_random_walk(step_options = [0, 0.5, 1], size = 100000):


    fig, axs = plt.subplots()
    plt.xlabel("Position - x")
    plt.ylabel("Position - y")

    Radius = 100
    step_addition = 0


    randomWalk_x= [0]
    randomWalk_y= [0]


    counter = 1


    while counter < (size + 1):
        i = counter

        angle = np.random.uniform(0, 2*np.pi, size = 1)
        distance = np.random.choice(step_options, size = 1)

        x_coordinate = distance[0] * np.cos(angle[0])
        y_coordinate = distance[0] * np.sin(angle[0])



        new_x = randomWalk_x[-1] + x_coordinate
        new_y = randomWalk_y[-1] + y_coordinate

        
        

        distance_from_origin = math.sqrt((new_x)**2 + (new_y)**2)

        if distance_from_origin >= (Radius):


            new_x = ('%.3f'%(new_x))
            new_y = ('%.3f'%(new_y))

            old_x = randomWalk_x[-1]
            old_y = randomWalk_y[-1] 

            old_x = ('%.3f'%(old_x))
            old_y = ('%.3f'%(old_y))           

            p1, p2 = Point(old_x, old_y) , Point(new_x, new_y)

            if p1.equals(p2):
                randomWalk_x.append(old_x)
                randomWalk_y.append(old_y)

                counter+=1
                
                continue
                


            line = Line(p1, p2)
            a, b, c = line.coefficients


            x, y = symbols('x,y')
            eq1 = Eq((x)**2 + (y)**2 - (Radius)**2, 0, evaluate=False)
            eq2 = Eq((a*x) + (b*y) + c, 0, evaluate=False)


            sol = solve([eq1, eq2], [x, y])


            #find the point on the circumference where our line will touch, call it circpoint
            try:
                sol1 = Point(sol[0][0], sol[0][1])
                sol2 = Point(sol[1][0], sol[1][1])                

                dist_sol1 = p1.distance(sol1)
                dist_sol2 = p1.distance(sol2)

                if dist_sol1 > dist_sol2:
                    circ_point = sol[1]
                elif dist_sol1 < dist_sol2:
                    circ_point = sol[0]
                else:
                    d1 = sol1.distance(p2)
                    d2 = sol2.distance(p2)

                    if d1 < d2:
                        circ_point = sol[0]
                    else:
                        circ_point = sol[1]

                    

                circ_point = Point(circ_point[0], circ_point[1])
            except:
                randomWalk_x.append(old_x)
                randomWalk_y.append(old_y)


                
                counter+=1
                continue
                

            #we know the overflow amount, call that overflowed
            overflowed = p2.distance(circ_point)


            #get the vector from our curr_pos to circpoint, call it incident
            incident = np.array([circ_point[0] - p1[0], circ_point[1] - p1[1]])


            #circpoint to origin vector
            normal = np.array([circ_point[0], circ_point[1]])


            #-find the angle between incident and normal using dot product wali equation, call that theta

            if p1.equals(circ_point):
                randomWalk_x.append(old_x)
                randomWalk_y.append(old_y)


                
                counter+=1
                
                continue            


            dot = (circ_point[0]*incident[0]) + (circ_point[1]*incident[1])

            magnitude1 = (circ_point[0]**2 + circ_point[1]**2)**(0.5)
            magnitude2 = (incident[0]**2 + incident[1]**2)**(0.5)

            ang = dot / (magnitude1 * magnitude2)

            main_ang = math.acos(ang)


            Theta = main_ang

            if p2[0] < 0 and p2[1] > 0:    #second
                Theta = -Theta

            elif p2[0] > 0 and p2[1] > 0:   #first
                if incident[1] >= incident[0]:
                    Theta = (-Theta)
                else:
                    Theta = (Theta)
            
            elif p2[0] > 0 and p2[1] < 0:
                if incident[1] > -incident[0]:   #fourth
                    Theta = (-Theta)

            elif p2[0] < 0 and p2[1] < 0:
                if incident[1] <= incident[0]:
                    Theta = (-Theta)
                


            

            #-form a 2x2 rotation matrix, uska format dekh lo aram se mile ga
            rotation_matrix = np.array([[np.cos(Theta), -np.sin(Theta)],[np.sin(Theta), np.cos(Theta)]])


            #-multiply the rotation matrix by the normal vector to get another 2x1 vector, call it reflected
            reflected = np.dot(rotation_matrix, normal)

            reflected *= -1


            #-find the unit vector in the direction of reflected, call it ref_unit
            ref_unit = reflected / math.sqrt(reflected[0]**2 + reflected[1]**2)


            #-scalar multiply ref_unit with overflow
            ref_point = ref_unit * overflowed

            #-us vector ke components ko add to circpoint ke coordinates to get the final coordinates
            final = circ_point + ref_point
            

            #-add both circ point (optional but will look better) and final coord to the arrays
            randomWalk_x.append(circ_point[0])
            randomWalk_y.append(circ_point[1])
            

            distance_from_origin = math.sqrt((final[0])**2 + (final[1])**2)

            counter+=1
            if distance_from_origin >= Radius:
                continue
            else:
                randomWalk_x.append(final[0])
                randomWalk_y.append(final[1])



            step_addition += 1
            continue


        randomWalk_x.append(new_x)
        randomWalk_y.append(new_y)
        counter += 1




    ### Uncomment to see plot
    #return distance_from_origin
    #########################


    size = size + step_addition

#########################################################
#UNCOMMENT FOR ANIMATION

    # xdata, ydata = [], []
    # ln, = plt.plot(xdata,ydata)

    # def init():
    #     #Radius = 5.64189584 when area of circle = 100 unit^2
    #     axs.set_xlim(-Radius,Radius)
    #     axs.set_ylim(-Radius,Radius)
    #     ln.set_data([], [])
    #     return ln,

    # def update(frame):
    #     xdata.append(randomWalk_x[int(frame)])
    #     ydata.append(randomWalk_y[int(frame)])
    #     ln.set_data(xdata, ydata)
    #     return ln,


    # ani = FuncAnimation(fig, update, frames=np.linspace(0, size, size+1, endpoint=True), interval = 20,
    #                 init_func=init, blit=True, repeat=False)


#ANIMATION CODE
########################################################


    circle1=plt.Circle((0,0),Radius,color='r', alpha= 0.2)
    plt.gcf().gca().add_artist(circle1)

    plt.plot(randomWalk_x, randomWalk_y)

    plt.show()
Exemplo n.º 11
0
target_p = np.array([300,0])

UAV = Point(UAV_p)
target = Point(target_p)
R0 = 100 # 最小转弯半径
phi0 = 1.745  # 速度方向 [0,2pi]
# 以上为所有已知信息

# 1. 求两个圆心,判断出采用哪一个圆
# 2. 求切线
# 3. 确定用那一段弧长

# 1.求两个圆心,判断出采用哪一个圆
c1 = Point(UAV.x + R0 * np.sin(phi0), UAV.y - R0 * np.cos(phi0))
c2 = Point(UAV.x - R0 * np.sin(phi0), UAV.y + R0 * np.cos(phi0))
len1 = c1.distance(target)
len2 = c2.distance(target)
minc=c1 if len1<len2 else c2
maxc=c1 if len1>len2 else c2
center=minc
type=2
if type == 0:
    if minc.distance(target) <= R0:
        # 如果小的dubins曲线到达不了,就用大的
        print('给定半径最短Dubins路径无法到达,R0=%d', R0)
        print(UAV.site)
        print(target[0:2])
        exec()
elif type == 1:
    if minc.distance(target) <= R0:
        # 如果小的dubins曲线到达不了,就用大的
Exemplo n.º 12
0
def findDistanceBWcomp(comp1, comp2):
    point1 = Point(int(comp1[0]), int(comp1[1]))
    point2 = Point(int(comp2[0]), int(comp2[1]))

    return int(point1.distance(point2))
Exemplo n.º 13
0
import numpy as np
from sympy import Matrix, init_printing, eye, symbols, simplify, sqrt, pprint, Point
from sympy.plotting import plot
init_printing(use_unicode=True)

x1, x2 = symbols('x1 x2')
a = Point([1, 0])
b = Point(3, -2)
a.distance(b)

J = Matrix(3, 3, [1, 0, 0, a.distance(b), 1, 0, 0, 0, -1])
M = Matrix(3, 3, [1, 0, 0, a.distance(b), 1, 0, 0, 0, -1])

pprint(M * Matrix([1, 1, 0]))
Exemplo n.º 14
0
    def sendFaceImages(self):
        self.statusLabel.set_text("Obrada uzoraka")
        detector = dlib.get_frontal_face_detector()
        predictor = dlib.shape_predictor("ldm.dat")

        for i in range(0, 7):
            gray = cv2.imread("Camera/Resources/" + str(i) + '.png', cv2.CV_8UC1)
            #gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

            rects = detector(gray, 1)

            # loop over the face detections
            for (j, rect) in enumerate(rects):
                shape = predictor(gray, rect)
                shape = face_utils.shape_to_np(shape)

                angle = self.calculateFaceTilt(Point(shape[39]), Point(shape[42]))

                gray = self.rotateImage(gray, angle, tuple(shape[33]))
                #gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
                rects = detector(gray, 1)

                # loop over the face detections
                for (k, rect) in enumerate(rects):

                    shape = predictor(gray, rect)
                    shape = face_utils.shape_to_np(shape)
                    eye = Point(shape[37])
                    eyebrow = Point(shape[19])
                    left = Point(min(shape, key=itemgetter(0)))
                    top = Point(min(shape, key=itemgetter(1)))
                    right = Point(max(shape, key=itemgetter(0)))
                    bottom = Point(max(shape, key=itemgetter(1)))

                    gray = gray[int(top.y - eye.distance(eyebrow) / 2):int(top.y + top.distance(bottom)),
                            int(left.x):int(left.x + left.distance(right))]

                    #ujednacavanje histograma
                    clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
                    gray = clahe.apply(gray)
                    #gray = cv2.bilateralFilter(gray, 9, 75, 75)

                    ratio = 300.0 / gray.shape[1]
                    dimensions = (300, int(gray.shape[0] * ratio))

                    gray = cv2.resize(gray, dimensions, interpolation=cv2.INTER_AREA)
                    cv2.imwrite("Camera/Resources/" + str(i) + '.png', gray)

        for i in range(0, 7):
            self.statusLabel.set_text("Slanje uzoraka")
            client.send("ftp:" + str(i))
            self.waitForResponse()
            imageFile = open("Camera/Resources/" + str(i) + '.png', "rb")
            offset = 0
            while True:
                sent = sendfile(client.fileno(), imageFile.fileno(), offset, 4096)
                if sent == 0:
                    client.send("EOF")
                    break  # EOF
                offset += sent
            self.statusLabel.set_text("Potvrdite PIN")
            self.btnConfirm.set_sensitive(True)
            self.waitForResponse()