packages/MC/geometry/RTK_Cell.cc
//---------------------------------------------------------------------------//
/*!
 * \brief Distance to a shell.
 *
 * d_db is set negative if there is no intersection with the shell.
 */
\brief Distance to a shell.
d_db is set negative if there is no intersection with the shell.
\ brief Distance to a shell . d_db is set negative if there is no intersection with the shell .
void RTK_Cell::dist_to_shell(double x,
                             double y,
                             double omega_x,
                             double omega_y,
                             double r,
                             int    face)
{
    d_db = -1.0;
    double a = omega_x * omega_x + omega_y * omega_y;
    double b = 2.0 * (x * omega_x + y * omega_y);
    double c = x * x + y * y - r * r;
    double discriminant = b * b - 4.0 * a * c;
    if (discriminant >= 0.0)
    {
        double sqr_root    = std::sqrt(discriminant);
        double denominator = 0.5 / a;
        double d1 = (-b + sqr_root) * denominator;
        double d2 = (-b - sqr_root) * denominator;
        if (d1 < 0.0)
            d_db = d2;
        else if (d2 < 0.0)
            d_db = d1;
        else if (face < d_num_shells)
            d_db = std::max(d1, d2);
        else
            d_db = std::min(d1, d2);
    }
}
void RTK_Cell :: dist_to_shell ( double x , double y , double omega_x , double omega_y , double r , int face ) { d_db = -1.0 ; double a = omega_x * omega_x + omega_y * omega_y ; double b = 2.0 * ( x * omega_x + y * omega_y ) ; double c = x * x + y * y - r * r ; double discriminant = b * b - 4.0 * a * c ; if ( discriminant >= 0.0 ) { double sqr_root = std :: sqrt ( discriminant ) ; double denominator = 0.5 / a ; double d1 = ( - b + sqr_root ) * denominator ; double d2 = ( - b - sqr_root ) * denominator ; if ( d1 < 0.0 ) d_db = d2 ; else if ( d2 < 0.0 ) d_db = d1 ; else if ( face < d_num_shells ) d_db = std :: max ( d1 , d2 ) ; else d_db = std :: min ( d1 , d2 ) ; } }
\brief Distance to a shell.
\ brief Distance to a shell .
// initialize distance to boundary // calculate terms in the quadratic // discriminant of quadratic // check for intersection with the surface anywhere along the line which // will be true if the discriminant > 0.0 (of course that doesn't mean the // ray will intersect the surface, just the line that the ray is on // intersects the surface) // calculate the sqrt of the discriminant and denominator once // calculate the roots of the equation // determine d, if both d1 and d2 < 0 then the ray does not intersect // the surface