3D无限锥线交叉公式

时间:2014-02-17 16:11:38

标签: intersection infinite raycasting

编辑:如果有人可以在评论中解释真正发生的事情,那将是非常棒的。我们基本上通过巧合找到了答案。

我正在尝试对无限大的锥体进行线性测试,但我无法理解我做错了什么。我确实得到某种像对象一样的圆锥体,但看起来......错了。

    EDIT: This is the solution for line-testing a infinite cone.
    double Cone::lineTest(double lineOrigin[3],double dir[3],double maxDistance) 

    {
    //Returns the distance from line origin to the collision point
    //The object is located at 0,0,0 so the difference is the lineOrigin
         double a = pow(D[0], 2) + pow(D[1], 2) - pow(D[2], 2);
         double b = 2*(O[0]*D[0] + O[1]*D[1] - O[2]*D[2]);
         double c = pow(O[0], 2) + pow(O[1], 2) - pow(O[2], 2);
         double d = b * b - 4*a*c;

         if(d < 0) 
             { return MAX_DISTANCE; }  
         d = sqrt(d);
         double sol1 = (-b - d)/(2.0*a);
         if(sol1 > 0) 
             return sol1;

    return MAX_DISTANCE;
    }

0 个答案:

没有答案