python——获取矩形四个角点的坐标
生活随笔
收集整理的這篇文章主要介紹了
python——获取矩形四个角点的坐标
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
任務描述
已知矩形中點[row, col],矩形主方向(自定義)與水平軸的夾角angle,長height,寬bottom。
獲取矩形四個角點的坐標。
代碼
def rect_loc(row, col, angle, height, bottom):assert angle <= 35, 'angle out of index'angle *= (10 / 180) * math.pi # 弧度xo = np.cos(angle)yo = np.sin(angle)y1 = row + height / 2 * yox1 = col - height / 2 * xoy2 = row - height / 2 * yox2 = col + height / 2 * xoreturn np.array([[y1 - bottom/2 * xo, x1 - bottom/2 * yo],[y2 - bottom/2 * xo, x2 - bottom/2 * yo],[y2 + bottom/2 * xo, x2 + bottom/2 * yo],[y1 + bottom/2 * xo, x1 + bottom/2 * yo],]).astype(np.int)if __name__ == '__main__':loc = rect_loc(200, 200, 0, 100, 40)print(loc)# 結果>>> [[180 150][180 250][220 250][220 150]]總結
以上是生活随笔為你收集整理的python——获取矩形四个角点的坐标的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 转载:全志问题解决方法
- 下一篇: 以太网交换机的工作原理