亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何擴展多邊形直到其中一個邊界達到一個點

如何擴展多邊形直到其中一個邊界達到一個點

catspeake 2021-04-06 17:17:31
我有擴展多邊形的代碼,它的工作原理是將xs和ys乘以一個系數,然后將所得的polyon重新居中在原始中心。給定多邊形需要達到的一點,我也有代碼來找到膨脹系數的值:import numpy as npimport itertools as ITimport copyfrom shapely.geometry import LineString, Pointdef getPolyCenter(points):    """    http://stackoverflow.com/a/14115494/190597 (mgamba)    """    area = area_of_polygon(*zip(*points))    result_x = 0    result_y = 0    N = len(points)    points = IT.cycle(points)    x1, y1 = next(points)    for i in range(N):        x0, y0 = x1, y1        x1, y1 = next(points)        cross = (x0 * y1) - (x1 * y0)        result_x += (x0 + x1) * cross        result_y += (y0 + y1) * cross    result_x /= (area * 6.0)    result_y /= (area * 6.0)    return (result_x, result_y)def expandPoly(points, factor):    points = np.array(points, dtype=np.float64)    expandedPoly = points*factor    expandedPoly -= getPolyCenter(expandedPoly)    expandedPoly += getPolyCenter(points)    return np.array(expandedPoly, dtype=np.int64)def distanceLine2Point(points, point):    points = np.array(points, dtype=np.float64)    point = np.array(point, dtype=np.float64)    points = LineString(points)    point = Point(point)    return points.distance(point)def distancePolygon2Point(points, point):    distances = []    for i in range(len(points)):        if i==len(points)-1:            j = 0        else:            j = i+1        line = [points[i], points[j]]        distances.append(distanceLine2Point(line, point))    minDistance = np.min(distances)    #index = np.where(distances==minDistance)[0][0]    return minDistance """    Returns the distance from a point to the nearest line of the polygon,    AND the distance from where the normal to the line (to reach the point)    intersets the line to the center of the polygon."""僅當點與多條線中的一條直接相對時,此代碼才有效。
查看完整描述

2 回答

  • 2 回答
  • 0 關注
  • 193 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號