【问题标题】:Collision detection - response between a moving sphere and a circular cylinder碰撞检测 - 运动球体和圆柱体之间的响应
【发布时间】:2015-03-11 09:52:50
【问题描述】:

我正在实现一个包含 3d 逻辑的简单游戏。为了检测运动的球体是否与圆柱体碰撞,程序或/和相关方程是什么?我的圆柱体是静态的正圆形并与 z 轴对齐。在这种情况下,我读到圆柱体的方程是 (x - a)² + (z - b)² = r²,其中

(a, b):圆柱体的中心 r:圆柱半径

如何使用它来查找两个对象是否相交,此外,如何应用球的相应响应?

谢谢

【问题讨论】:

    标签: 3d geometry collision-detection game-physics


    【解决方案1】:

    通常圆柱到球体测试可以简化为点到线段测试,其中:

    1. 线段表示穿过中心的线 从头到尾的圆柱体端点是已知的。
    2. 该点表示球体的 centerPoint。
    3. 测试在线段上找到一个最接近 centerPoint 的点 并简单地测量点之间的距离,如果它更小 比球半径 + 圆柱半径,它正在碰撞。

    对此的折衷方案是它可以有效地使其成为一个球体到胶囊的测试,而不是球体到圆柱体。如果你能接受这种妥协,这里有一些伪代码。

    vector cylCenterVector = endPoint2 - endpoint1;
    float distanceFactorFromEP1 = Dot(sphereCenter - endPoint1) / Dot(cylCenterVector , cylCenterVector );
    if(distanceFactorFromEP1 < 0) distanceFactorFromEP1 = 0;// clamp to endpoints if neccesary
    if(distanceFactorFromEP1 > 1) distanceFactorFromEP1 = 1;
    vector closestPoint = endPoint1 + (cylCenterVector * distanceFactorFromEP1);
    
    vector collisionVector = sphereCenter - closestPoint;
    float distance = collisionVector.Length();
    vector collisionNormal = collisionVector / distance;
    
    if(distance < sphereRadius + cylRadius)
    {
      //collision occurred. use collisionNormal to reflect sphere off cyl
    
      float factor = Dot(velocity, collisionNormal);
    
      velocity = velocity - (2 * factor * collisionNormal);
    
    }
    

    【讨论】:

    • 胶囊是什么意思?你的意思是圆柱的顶部和底部会有半个球体吗?
    • 只是指出一个错误,我认为第一个点积中应该有一个 cylCenterVector:Dot(sphereCenter - endPoint1,cylCenterVector) / Dot(cylCenterVector , cylCenterVector)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多