给定具有已知起点(x,y),结束(x,y)和角度的弧,如何计算其边界框?

时间:2016-09-15 14:12:24

标签: python math geometry bounding-box

标题说明了一切。给定一个弧(例如):

Start Point: x = 53.34, y = 52.07
End Point: x = 13.97, y = 52.07
Angle: 180 degrees

enter image description here 我怎样才能找到它的边界框?

即使我在python中编写,puesdocode也是首选,因此它对其他人有用。

谢谢!

- 汤姆

1 个答案:

答案 0 :(得分:1)

h = Sqrt( (start.x - end.x)^2 + (start.y - end.y)^2)
or
h = Math.Hypot(start.x - end.x, start.y - end.y)

R = Abs(h / (2*Sin(Angle/2)))

if angle <= Pi/2
    top = end.y
    left = end.x
    bottom = start.y
    right = start.x
else if angle <= Pi 
    top = start.y - R
    left = end.x
    bottom = start.y
    right = start.x
else if angle <= 3*Pi/2 
    top = start.y - R
    left = start.x - 2*R
    bottom = end.y
    right = start.x
else 
    top = start.y - R
    left = start.x - 2*R
    bottom = start.y + R
    right = start.x