Python风向切面均匀提取风轨迹线

14 篇文章 0 订阅

暂时没有图,思路就是,计算总风向的切面,根据切面所在的函数,求切面的长宽高(坐标点三角函数),传入需要提取线数的N值,由于等分矩阵y=x^2,所以递归切割面,当y>n时,提取集合前n条线,同时在切割面中取起伏最大的一条线

def UniformExtractLines(listLines , OutLines, WindDirection):
    list_xyz = GetlinesLastPointList(listLines)
    #风向向量
    vq=getAngel_xy(WindDirection)
    k=-vq[0]/vq[1]
    #k=math.tan(angle_xk)
    angle_xk=math.atan(k)
    InitialPoint =[0,0]
    terminationPoint=[0,0]
    len_L=0
    list_y = []
    if (k>1) or (k<-1 and k<0):
        for i in range(len(list_xyz)):
            y = list_xyz[i][1]*math.sin(angle_xk)
            points_y = y,list_xyz[i][2],list_xyz[i][4]
            list_y.append(points_y)
        array_y = np.array(list_y)
        max_y = max(array_y[:,0])
        min_y = min(array_y[:,0])
        InitialPoint[0] = min_y
        terminationPoint[0] = max_y
        len_L = max_y-min_y
    list_x = []
    if (k >-1 and k<0) or (k > 0 and k <1):
        for i in range(len(list_xyz)):
            x= list_xyz[i][0] * math.cos(angle_xk)
            points_x= x,list_xyz[i][2],list_xyz[i][4]
            list_x.append(points_x)
        array_x = np.array(list_x)
        max_x = max(array_x[:,0])
        min_x = min(array_x[:,0])
        InitialPoint[0]=min_x
        terminationPoint[0] = max_x
        len_L = max_x - min_x

    array_xyz = np.array(list_xyz)
    max_h = max(array_xyz[:, 2])
    min_h = min(array_xyz[:, 2])
    height_L=max_h-min_h
    InitialPoint[1] = min_h
    terminationPoint[1] = max_h

    list_lineIndex = RecursionGetLines(OutLines, InitialPoint, k, list_y, list_x,height_L,len_L, 0)

    list_ResultLines=[]
    #索引循环对应的线集合,取起伏最大的线段
    for x in range(len(list_lineIndex)):
        list_fluctuate=[]
        for y in list_lineIndex[x]:
            array_line=np.array(listLines[y])
            line_Up= max(array_line[:, 2])
            line_Down=min(array_line[:, 2])
            fluctuate=line_Up-line_Down
            flu=fluctuate,y
            list_fluctuate.append(flu)
        sorted(list_fluctuate,key=lambda x:x[0])
        result=listLines[list_fluctuate[0][1]]
        list_ResultLines.append(result)

    return list_ResultLines
def RecursionGetLines(OutLines,InitialPoint,k,list_y,list_x,height_L,len_L,number):
    SquareMatrix_Len = int(math.sqrt(OutLines)) + number
    h_spaceBetween = height_L / SquareMatrix_Len
    l_spaceBetween = len_L / SquareMatrix_Len
    # 分割矩阵顶点坐标集合
    list_rectangle = []
    for i in range(0, SquareMatrix_Len):
        for l in range(0, SquareMatrix_Len):
            l_l = InitialPoint[0] + i * l_spaceBetween
            l_r = InitialPoint[0] + (i + 1) * l_spaceBetween
            h_l = InitialPoint[1] + l * h_spaceBetween
            h_r = InitialPoint[1] + (l + 1) * h_spaceBetween
            list_r_p = l_l, l_r, h_l, h_r
            list_rectangle.append(list_r_p)
    list_lineIndex = []
    if (k > 1) or (k < -1 and k < 0):
        for i in range(len(list_rectangle)):
            listIndex = []
            for h in range(len(list_y)):
                if (list_y[h][0] > list_rectangle[i][0] and list_y[h][0] < list_rectangle[i][1]) and (
                        list_y[h][2] > list_rectangle[i][2] and list_y[h][2] < list_rectangle[i][3]):
                    listIndex.append(list_y[h][2])
            if len(listIndex) > 0:
                list_lineIndex.append(listIndex)

    if (k > -1 and k < 0) or (k > 0 and k < 1):
        for i in range(len(list_rectangle)):
            listIndex = []
            for h in range(len(list_x)):
                if (list_x[h][0] >= list_rectangle[i][0] and list_x[h][0] <= list_rectangle[i][1]) and (
                        list_x[h][1] >= list_rectangle[i][2] and list_x[h][1] <= list_rectangle[i][3]):
                    listIndex.append(list_x[h][2])
            if len(listIndex) > 0:
                list_lineIndex.append(listIndex)
    if len(list_lineIndex) < OutLines:
        number=number+1
        list_lineIndex= RecursionGetLines(OutLines, InitialPoint, k, list_y, list_x, height_L,len_L,number)
    if len(list_lineIndex) >= OutLines:
        list_lineIndex=list_lineIndex[0:OutLines]
    return list_lineIndex
def GetlinesLastPointList(listLines):
    list_xyz = []
    for i in range(len(listLines)):
        h=len(listLines[i]) - 1
        result=listLines[i][h][0],listLines[i][h][1],listLines[i][h][2],listLines[i][h][3],i
        list_xyz.append(result)
    return list_xyz
def getAngel_xy(correctAngel):
    x=0
    y=0
    if correctAngel> 0 and correctAngel <90:
        x = -round(math.sin(math.radians(correctAngel)), 10)
        y = -round(math.cos(math.radians(correctAngel)), 10)
    if correctAngel> 90 and correctAngel <180:
        correctAngel = correctAngel-90
        x = -round(math.cos(math.radians(correctAngel)), 10)
        y = round(math.sin(math.radians(correctAngel)), 10)
    if correctAngel > 180 and correctAngel < 270:
        correctAngel = correctAngel-180
        x = round(math.sin(math.radians(correctAngel)), 10)
        y = round(math.cos(math.radians(correctAngel)), 10)
    if correctAngel> 270 and correctAngel <360:
        correctAngel = correctAngel-270
        x = round(math.cos(math.radians(correctAngel)), 10)
        y = -round(math.sin(math.radians(correctAngel)), 10)
    if correctAngel==0 or correctAngel== 360:
        x =0
        y = -1
    if correctAngel==90:
        x = -1
        y = 0
    if correctAngel == 180:
        x = 0
        y = 1
    if correctAngel == 270:
        x = 1
        y = 0
    return x,y

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值