title: Raytracing a cone along an arbitrary axis
body: <p>I'm working on a RayTracer and I can't figure out what I'm doing wrong when I try to calculate an intersection with a cone. I have my ray vector and the position of the cone with its axis. I know that compute a cone along a simple axis is easy but I want to do it with an arbitrary axis.</p>
  
  <p>I'm using this link <a href="http://mrl.nyu.edu/~dzorin/rend05/lecture2.pdf" rel="nofollow">http://mrl.nyu.edu/~dzorin/rend05/lecture2.pdf</a> for the cone equation (page 7-8) and here is my code :</p>
  
  <pre><code>alpha = cone-&gt;angle * (PI / 180);
  axe.x = 0;
  axe.y = 1;
  axe.z = 0;
  
  delt_p = vectorize(cone-&gt;position, ray.origin);
  tmp1.x = ray.vector.x - (dot_product(ray.vector, axe) * axe.x);
  tmp1.y = ray.vector.y - (dot_product(ray.vector, axe) * axe.y);
  tmp1.z = ray.vector.z - (dot_product(ray.vector, axe) * axe.z);
  tmp2.x = (delt_p.x) - (dot_product(delt_p, axe) * axe.x);
  tmp2.y = (delt_p.y) - (dot_product(delt_p, axe) * axe.y);
  tmp2.z = (delt_p.z) - (dot_product(delt_p, axe) * axe.z);
  
  a = (pow(cos(alpha), 2) * dot_product(tmp1, tmp1)) - (pow(sin(alpha), 2) * dot_product(ray.vector, axe));
  b = 2 * ((pow(cos(alpha), 2) * dot_product(tmp1, tmp2)) - (pow(sin(alpha), 2) * dot_product(ray.vector, axe) * dot_product(delt_p, axe)));
  c = (pow(cos(alpha), 2) * dot_product(tmp2, tmp2)) - (pow(sin(alpha), 2) * dot_product(delt_p, axe));
  delta = pow(b, 2) - (4 * a * c);
  
  if (delta &gt;= 0)
  {
      t1 = (((-1) * b) + sqrt(delta)) / (2 * a);
      t2 = (((-1) * b) - sqrt(delta)) / (2 * a);
      t = (t1 &lt; t2 ? t1 : t2);
      return (t);
  }
  </code></pre>
  
  <p>I initialised my axis with the y axis so I can rotate it.
  Here is what I get : <a href="http://i.imgur.com/l3kaavc.png" rel="nofollow">http://i.imgur.com/l3kaavc.png</a>
  Instead of a cone, I have that paraboloid red shape on the right, and I know that it's almost the same equation as a cone.</p>