title: Raytracing and Surface normals
body: <p>I am having a weird problem in the below code snippet. I am trying to use surface normals of a sphere(outward) to determine the correct ray intersection and eliminate those that are hitting from within the sphere. for some strange reason this only works correctly when I flip my surface normal to be inwards and change my inequality to be &gt;= 0 and I'm struggling to see what I'm doing wrong.</p>
  <pre><code>if (discriminant &gt;= 0) {
    float solution_1 = (-b + sqrt(discriminant)) / 2 * a;
    Vec3 normal_1 = (m_Centre, r.direction() * solution_1);
    if (dot(normal_1, r.direction()) &lt;= 0) {
      colour_depth.first = m_Colour;
      colour_depth.second = (r.direction() * solution_1)[2];
      return colour_depth;
    }
  
    float solution_2 = (-b - sqrt(discriminant)) / 2 * a;
    Vec3 Normal_2 = (m_Centre, r.direction() * solution_2);
    if (dot(Normal_2, r.direction()) &lt;= 0) {
      colour_depth.first = m_Colour;
      colour_depth.second = (r.direction() * solution_2)[2];
      return colour_depth;
    }
    else {
      colour_depth.first = Vec3(0.0, 0.0, 1.0);
      colour_depth.second = -10000.f;
      return colour_depth;
    }
  }
  else {
    colour_depth.first = Vec3(0.0, 0.0, 1.0);
    colour_depth.second = -1000000.f;
    return colour_depth;
  }
  }
  
  Vec3 Normal(Vec3 Origin, Vec3 Intersection) {
    Vec3 n = (Intersection - Origin).normalise();
    return n;
  }
  </code></pre>