Hello,
I am trying to learn how to put together a basic ray tracer which can model spheres and planes. I have an example ray tracer which I am currently pulling apart and sifting through line by line to try and understand exactly how it works. I have come to a point in the code which I am having trouble explaining adequately. It's a method of the Plane class, which is a class defining the planes in the scene. The method is called findIntersection and I believe its purpose is to return the distance between the origin of the ray and the point of intersection, it looks like this
1 2 3 4 5 6 7 8 9 10 11 12
|
double findIntersection(Ray ray){
Vector ray_direction=ray.getDirection();
double a = ray_direction.DotProduct(normal);
if(a==0){
return -1;
}
else{
double b=normal.DotProduct(ray.getStart()+((normal*distance).Inverse()));
return -1*b/a;
}
}
|
The method accepts arguments of type Ray which is a class defining rays, rays are constructed from this class by supplying two vectors, a starting vector and a direction vector, the Ray class has a method function getDirection which is used in the first line of the findIntersection function which clearly just returns the direction vector. The DotProduct method being accessed belongs to the Vector class and is a standard method for finding the dot product of two vectors. "normal" is a variable of type Vector and is used in the construction of an instance of the Plane class, along with a distance from the centre of the scene and a colour. Also, in the line
double b=normal.DotProduct(ray.getStart()+((normal*distance).Inverse()));
the plus sign between the two vectors is an overloaded operator which adds the two vectors in the usual mathematical way, I overloaded it for neatness.
The trouble I'm having is working out what the variables a and b are doing, what they mean geometrically and how they correspond to getting the distance between ray origin and point of intersection. Any help with explaining what these variables do would be great, thanks.