Sphere.h
double intersect(Ray r) {
    //calculate determinant of intersection equation
    /*std::cout<<(r.d).dot(Eigen::Vector4d(1.0,0.0,0.0,0.0))<<' '
    <<(r.d).dot(Eigen::Vector4d(0.0,1.0,0.0,0.0))<<' '<<(r.d).dot(Eigen::Vector4d(0.0,0.0,1.0,0.0))<<std::endl;*/
    double det = (r.d.dot(r.e-c))*(r.d.dot(r.e-c)) - (r.d.dot(r.d))*((r.e-c).dot(r.e-c)-rad*rad);
    //std::cout<<det<<std::endl;2
    if (det < 0) {
      return -1;
    }
    else { //problem has 2 solutions
      //solution 1 where t = (-b + sqrt(desc))/2a
      double sol1 = (sqrt(det) - r.d.dot(r.e-c))/(r.d.dot(r.d));
      //solution 2 where t = -(b + sqrt(desc))/2a
      double sol2 = -(sqrt(det) + r.d.dot(r.e-c))/(r.d.dot(r.d));
      double closeSol = fmin(sol1,sol2);

      //if the solution occurs between the start and end times
      if (r.start<closeSol && closeSol<r.end ) {
        return closeSol;
      }
      else {
        return -1;
      }
    }
  }
/*returns the time value at the intersection of the ray and sphere*/
returns the time value at the intersection of the ray and sphere
returns the time value at the intersection of the ray and sphere
double intersect(Ray r) {
    double det = (r.d.dot(r.e-c))*(r.d.dot(r.e-c)) - (r.d.dot(r.d))*((r.e-c).dot(r.e-c)-rad*rad);
    if (det < 0) {
      return -1;
    }
    else { 
      double sol1 = (sqrt(det) - r.d.dot(r.e-c))/(r.d.dot(r.d));
      double sol2 = -(sqrt(det) + r.d.dot(r.e-c))/(r.d.dot(r.d));
      double closeSol = fmin(sol1,sol2);
      if (r.start<closeSol && closeSol<r.end ) {
        return closeSol;
      }
      else {
        return -1;
      }
    }
  }
double intersect ( Ray r ) { double det = ( r . d . dot ( r . e - c ) ) * ( r . d . dot ( r . e - c ) ) - ( r . d . dot ( r . d ) ) * ( ( r . e - c ) . dot ( r . e - c ) - rad * rad ) ; if ( det < 0 ) { return -1 ; } else { double sol1 = ( sqrt ( det ) - r . d . dot ( r . e - c ) ) / ( r . d . dot ( r . d ) ) ; double sol2 = - ( sqrt ( det ) + r . d . dot ( r . e - c ) ) / ( r . d . dot ( r . d ) ) ; double closeSol = fmin ( sol1 , sol2 ) ; if ( r . start < closeSol && closeSol < r . end ) { return closeSol ; } else { return -1 ; } } }
returns the time value at the intersection of the ray and sphere
returns the time value at the intersection of the ray and sphere
//calculate determinant of intersection equation /*std::cout<<(r.d).dot(Eigen::Vector4d(1.0,0.0,0.0,0.0))<<' '
    <<(r.d).dot(Eigen::Vector4d(0.0,1.0,0.0,0.0))<<' '<<(r.d).dot(Eigen::Vector4d(0.0,0.0,1.0,0.0))<<std::endl;*/ //std::cout<<det<<std::endl;2 //problem has 2 solutions //solution 1 where t = (-b + sqrt(desc))/2a //solution 2 where t = -(b + sqrt(desc))/2a //if the solution occurs between the start and end times