使用 upper_left 和 bottom_right 繪制一個矩形是很常見的,但我只有寬度邊的中點。

這看起來可行,因為它與 x 軸完美對齊,但我不確定當這兩個坐標成角度時如何實作。
我試圖獲得 upper_left 和 bottom_right 坐標,但以某個角度計算它們是一個挑戰

uj5u.com熱心網友回復:
這是我獲得四個角的方法:
def get_corners(point1,point2,width):
# width /= 2
m1 = (point1[1]-point2[1])/(point1[0]-point2[0])
m2 = -1/m1
cor_x = math.sqrt((width/2)**2 / (m2**2 1))
cor_y = math.sqrt((width/2)**2 / (m2**-2 1))
if m2 >= 0:
corner1 = (point1[0] cor_x, point1[1] cor_y)
corner2 = (point1[0] - cor_x, point1[1] - cor_y)
corner3 = (point2[0] cor_x, point2[1] cor_y)
corner4 = (point2[0] - cor_x, point2[1] - cor_y)
else:
corner1 = (point1[0] - cor_x, point1[1] cor_y)
corner2 = (point1[0] cor_x, point1[1] - cor_y)
corner3 = (point2[0] - cor_x, point2[1] cor_y)
corner4 = (point2[0] cor_x, point2[1] - cor_y)
return corner1, corner2, corner3, corner4
print(get_corners((4,8),(-4,-8),math.sqrt(80)))
結果:
((0.0, 10.0), (8.0, 6.0), (-8.0, -6.0), (0.0, -10.0))
對應于:
使用的矩形
之后,只需根據您的 upper_left/bottom_right 方法像往常一樣繪制所有線條
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/447481.html
上一篇:按鈕不更新的背景-Andorid
下一篇:從多個url中提取影像
