title: Why does raytracer render spheres as ovals?
body: <p>I've been hacking up a raytracer for the first time over the past few days. However, there are a few quirks which bother me and I don't really know how to work out. One that has been there since the beginning is the shape of spheres in the scene - when rendered, they actually look like ovals. Of course, there is perspective in the scene, but the final shape still seems odd. I have attached a sample rendering, the problem I have is especially visible on the reflective sphere in the lower left part of the image.</p>
  
  <p><img src="https://i.stack.imgur.com/d02ec.png" alt="Sample Image"></p>
  
  <p>I don't really know what could be causing this. It might be the ray-sphere intersection code which looks as follows:</p>
  
  <pre><code>bool Sphere::intersect(Ray ray, glm::vec3&amp; hitPoint) {
  //Compute A, B and C coefficients
  float a = glm::dot(ray.dir, ray.dir);
  float b = 2.0 * glm::dot(ray.dir, ray.org-pos);
  float c = glm::dot(ray.org-pos, ray.org-pos) - (rad * rad);
  
  // Find discriminant
  float disc = b * b - 4 * a * c;
  
  // if discriminant is negative there are no real roots, so return
  // false as ray misses sphere
  if (disc &lt; 0)
      return false;
  
  // compute q
  float distSqrt = sqrt(disc);
  float q;
  if (b &lt; 0)
      q = (-b - distSqrt)/2.0;
  else
      q = (-b + distSqrt)/2.0;
  
  // compute t0 and t1
  float t0 = q / a;
  float t1 = c / q;
  
  // make sure t0 is smaller than t1
  if (t0 &gt; t1) {
      // if t0 is bigger than t1 swap them around
      float temp = t0;
      t0 = t1;
      t1 = temp;
  }
  
  // if t1 is less than zero, the object is in the ray's negative direction
  // and consequently the ray misses the sphere
  if (t1 &lt; 0)
      return false;
  
  // if t0 is less than zero, the intersection point is at t1
  if (t0 &lt; 0) {
      hitPoint = ray.org + t1 * ray.dir;
      return true;
  } else { // else the intersection point is at t0
      hitPoint = ray.org + t0 * ray.dir;
      return true;
      }
  }
  </code></pre>
  
  <p>Or it could be another thing. Does anyone have an idea? Thanks so much! </p>