给定起点 (x, y)、终点 (x, y) 和角度已知的弧,如何计算其边界框?
Given an arc with a known start(x, y), end(x, y) and angle, how can I calculate its bounding box?
标题说明了一切。给定一个圆弧(例如):
Start Point: x = 53.34, y = 52.07
End Point: x = 13.97, y = 52.07
Angle: 180 degrees
我怎样才能找到它的边界框?
虽然我是用python写的,但还是首选puesdocode,这样对其他人有用。
谢谢!
-汤姆
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
标题说明了一切。给定一个圆弧(例如):
Start Point: x = 53.34, y = 52.07
End Point: x = 13.97, y = 52.07
Angle: 180 degrees
虽然我是用python写的,但还是首选puesdocode,这样对其他人有用。
谢谢!
-汤姆
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