给定一个具有已知起点(x,y)、终点(x,y)和角度的圆弧,如何计算其边界框?

2024-05-02 20:30:08 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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是首选,因此它对其他人也很有用。在

谢谢!在

-汤姆


Tags: 标题startendpoint边界degreesanglepuesdocode
1条回答
网友
1楼 · 发布于 2024-05-02 20:30:08
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

相关问题 更多 >