【问题标题】:Given an arc with a known start(x, y), end(x, y) and angle, how can I calculate its bounding box?给定一个已知起点(x,y),终点(x,y)和角度的弧,我如何计算它的边界框?
【发布时间】:2017-01-23 14:41:48
【问题描述】:

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

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

如何找到它的边界框?

虽然我是用 python 写的,但还是首选 puesdocode,这样它对其他人有用。

谢谢!

-汤姆

【问题讨论】:

  • 信息(起点、终点、角度)不能唯一标识弧。在您的示例中,它也可能是圆的另一半(或者对于那个,角度是-180?)。
  • 在这种情况下,我是否可以假设正角度始终意味着特定方向? (即:圆的另一半的角度 = -180)
  • 我认为MathOverflowMath 会更适合这个问题。作为对您问题的回答:我想您可以。但为了严谨起见,请对三角(逆时针)角度使用正角度值。
  • 我很抱歉。是否有移动问题机制?
  • 不确定(我不这么认为)。不过你这里已经有了答案,所以我想没关系。

标签: python math geometry bounding-box


【解决方案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

【讨论】:

  • 太棒了!我的python版本:tutorialspoint.com/…
  • 实际上,我不确定它是否正常工作 - 我希望看到顶部和底部(边界框的高度)之间的差异为 39.370。
  • 例如 R = (53.34-13.97)/2=39.37/2=19.685 - 这是盒子的高度。它的宽度是 39.37。
  • 当我使用你的公式计算 R 时,我得到了截然不同的答案。不知道我做错了什么? pastebin.com/bukZjhPu
  • 我忘记了计算距离 (h) 的平方根。已编辑。如果你有Math.Hypot函数,用它来查找h。
猜你喜欢
  • 2020-12-28
  • 1970-01-01
  • 1970-01-01
  • 2017-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-16
  • 1970-01-01
相关资源
最近更新 更多