navigationAlgoCode.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:EWB-Drones-Navigation 作者: Rip-Lyster 项目源码 文件源码
def getLineEnd(x, yStart, perimeterPoints):
    """accepts:
            (x,yStart): position of perimeter point
            perimeterPoints: list of perimeter points, used to check which one is immediately below (x,yStart)
         returns:
            yEnd: when combined into (x,yEnd), it is the coordinates of the point on the perimeter immediately below (x,yStart)
                NOTE: yEnd is None if there is no such point
    """
    pointsBelow = 0
    yEnd = None
    for index1 in range(len(perimeterPoints)):
        index2 = (index1 + 1)%len(perimeterPoints)
        if (x, yStart) == perimeterPoints[index1] \
        or (x, yStart) == perimeterPoints[index2]:
            continue
        x0, x1 = perimeterPoints[index1][0], perimeterPoints[index2][0]
        if min(x0, x1)<= x <= max(x0, x1) and x0 != x1:
            #print(x0, x1)
            y0, y1 = perimeterPoints[index1][1], perimeterPoints[index2][1]
            #if math.isclose(x0, x1):
            #    y = max(y0, y1)
                #print(y,"!")
            #else:
            y = (y1-y0)/(x1-x0) * (x-x0) + y0
            if y > yStart and (yEnd == None or y < yEnd):
                pointsBelow += 1
                yEnd = y
    if pointsBelow % 2 == 0: yEnd = None
    return yEnd
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号