3D cone endless line intersection formula

EDIT: It would be great if someone could explain in the comment what is really happening. We basically figured out the answer by coincidence.

I'm trying to do linear tests against an infinitely large cone, but it's hard for me to understand what I'm doing wrong. I get some kind of cone-shaped object to show it, but it looks ... wrong.

    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;
    }
+3
source share

All Articles