7 Replies Latest reply: Apr 2, 2007 11:22 AM by 796447 RSS

    Broken Booleans

      I am very confused to say the least with my current assignment in class.

      I am making a Ray Tracer that can see a sphere and only a sphere, so far. So here is my code for detecting an intersection with a ray and my sphere
      double b = 2 * ((ray.rayD.x * (ray.rayO.x - center.x)) + (ray.rayD.y * (ray.rayO.y - center.y)) + (ray.rayD.z *(ray.rayO.z - center.z)));
              double c = Math.pow(ray.rayO.x - center.x, 2) + Math.pow(ray.rayO.y - center.y, 2) + Math.pow(ray.rayO.z - center.z, 2) + Math.pow(radius, 2);
              double ct = (b*b)-4*c;
              if(ct < 0)
                  return ScenceObject.INFINITY;
                  return Math.sqrt(ct/2);
      The problem is that if(ct < 0) always returns false. And the program returns NaN or zero all the time.

      Any help will be appreciated. If it makes a difference I run Ubuntu 6.11 with netbeans. I have to use the debian version of Java 6, apt-get java 6. It is the only way I can get java to work on this machine.