case 4: // Third order polynomial // Check whether the 4 centers co-planar PlaneNormal = cross(Segment->Center_Coef[1]-Segment->Center_Coef[0], Segment->Center_Coef[2]-Segment->Center_Coef[0]); if (fabs(dot(PlaneNormal,Segment->Center_Coef[3]-Segment->Center_Coef[0])) < EPSILON) { PointsCoplanar = true; PlaneNormal.normalize(); if (fabs(dot(PlaneNormal,ray.Direction)) > 1.0-EPSILON) RayPerpToCoplanarPoints = true; } if (RayPerpToCoplanarPoints) { // If have coplanar points and ray direction perpendicular to that plane, special handling. // // Massimo Valentini, described the issue this way: // // The problem is that the intersection between a planar speresweep and a ray // orthogonal to the plane is ill-conditioned. The equation is a polynomial // that is a perfect square: // // p(d) = p2(d) * p2(d) // // meaning that it is always non negative and zero only on the surface. // // Get the intersection with plane NormalDotDirection = dot(PlaneNormal,ray.Direction); if (NormalDotDirection >= EPSILON) { t = fabs(dot(Segment->Center_Coef[0] - ray.Origin, PlaneNormal) / NormalDotDirection); // Hack in the intersection pending some magic not invented... if((t > -MAX_DISTANCE) && (t < MAX_DISTANCE)) { IPoint = ray.Evaluate(t); if (this->Inside(IPoint, Thread)) { // Add intersection Isect[Isect_Count].t = t; // Calculate point Isect[Isect_Count].Point = IPoint; // Set normal Isect[Isect_Count].Normal = PlaneNormal; Isect_Count++; } } } Num_Poly_Roots = 0; } else