Math 如何显示两个对象是否在三维空间中移动

Math 如何显示两个对象是否在三维空间中移动,math,3d,game-engine,game-physics,Math,3d,Game Engine,Game Physics,我正在开发另一个3d游戏引擎,有以下问题。为了提高性能,我想检查两个对象是否彼此靠近或远离。只有当它们彼此靠近时,才会发生碰撞检测 此时,代码使用两个对象的位置计算当前距离。然后围绕速度向量移动两个位置并计算预期距离。等等 public class Model{ public boolean isApproaching(Model model) { float [] otherPosition = model.getPosition(); float [

我正在开发另一个3d游戏引擎,有以下问题。为了提高性能,我想检查两个对象是否彼此靠近或远离。只有当它们彼此靠近时,才会发生碰撞检测

此时,代码使用两个对象的位置计算当前距离。然后围绕速度向量移动两个位置并计算预期距离。等等

public class Model{

    public boolean isApproaching(Model model) {
        float [] otherPosition = model.getPosition();
        float [] otherVelocity = model.getVelocity();
        double currentDistance = Math.pow(this.position[0] - otherPosition[0], 2)
                                + Math.pow(this.position[1] - otherPosition[1], 2)
                                + Math.pow(this.position[2] - otherPosition[2], 2);
        double expectedDistance = Math.pow(this.position[0] + this.velocityVector[0]/1000 - otherPosition[0] - otherVelocity[0]/1000, 2)
                                + Math.pow(this.position[1] + this.velocityVector[1]/1000 - otherPosition[1] - otherVelocity[1]/1000, 2)
                                + Math.pow(this.position[2] + this.velocityVector[2]/1000 - otherPosition[2] - otherVelocity[2]/1000, 2);
        if(currentDistance < expectedDistance)
            return false;
        return true;
    }

}
公共类模型{
公共布尔Isapproach(模型){
float[]otherPosition=model.getPosition();
float[]otherVelocity=model.getVelocity();
双电流距离=数学功率(此位置[0]-其他位置[0],2)
+Math.pow(此位置[1]-其他位置[1],2)
+Math.pow(这个位置[2]-其他位置[2],2);
双预期距离=数学功率(此位置[0]+此速度向量[0]/1000-其他位置[0]-其他速度[0]/1000,2)
+Math.pow(this.position[1]+this.velocityVector[1]/1000-otherPosition[1]-otherVelocity[1]/1000,2)
+Math.pow(this.position[2]+this.velocityVector[2]/1000-otherPosition[2]-otherVelocity[2]/1000,2);
if(当前距离<预期距离)
返回false;
返回true;
}
}
如图所示,它不适用于快速移动的对象。有没有什么好方法可以显示两个点是否朝着对方移动


考虑到两条直线的轨迹,它们最接近的时间是独一无二的,这可能已经过去了。如果是在过去,那么这意味着物体正在彼此远离,但如果是在未来,则意味着它们正在彼此靠近。但即使他们的关系越来越密切,我猜你也应该知道你需要的信息需要多长时间,这样你就可以安排什么时候担心它了。此方法应同时适用于缓慢移动和快速移动的对象。

与任何其他值相比,您使用的
/1000
似乎是出于某些未说明的原因,可能会否定以下内容


通过更改此比例因子,可以更好地检测快速对象。执行相同的
isapproach()
计算,除非使用
/(1000*N)
而不是
/1000
。然后,你将有N倍的灵敏度来知道它们是否正在接近。

我将尝试使用它们方向向量的叉积。要么这样,要么求解它们的交点。1000是一个随机值,应该使两个对象“减速”,以避免情况2。你的解决方案听起来更好。谢谢。曾在空中交通管制部门工作过,这提供了一些见解。要提高性能,为什么不使用整数数学或只使用
double
并避免
float
转换为double时间@搅拌机交叉产品的想法也是好的。