【问题标题】:find distance in line-circle intersection求线圆交点的距离
【发布时间】:2019-06-13 08:40:31
【问题描述】:

一条线与圆心在C (cx,cy) 和半径r 相交。该线由位置P (px, py) 和方向D (dx, dy) 描述。 P 位于圆圈内,线无限长。 dP 到交叉点的距离是多少?

float Intersect(Vector2d C, float r, Vector2d P, Vector2d D){

    ...

    return d;
}

【问题讨论】:

  • 您可以将 C 转换为原点并应用 here 中的公式得到交点 I。然后计算 I 和 P 之间的距离。

标签: geometry collision-detection intersection


【解决方案1】:

您可以扩展括号并求解未知t的二次方程:

((px - cx) + t * dx)^2 + ((py - cy) + t * dy)^2 = r^2

如果(dx,dy) 向量被归一化(单位长度),那么t 的值(如果你的线真的是从圆内开始的射线,则为正根)是需要距离。

交点公式(当前语句不需要)

ix = px + t * dx
iy = py + t * dy

【讨论】:

    猜你喜欢
    • 2018-01-17
    • 1970-01-01
    • 2019-10-31
    • 1970-01-01
    • 1970-01-01
    • 2015-08-25
    • 2012-10-14
    • 1970-01-01
    • 2022-01-06
    相关资源
    最近更新 更多