Everything,
I am writing a rather unusual beam tracer to calculate the heat transfer properties of various objects in a scene. In this beam detector, random beams are taken from the surface of my primitive objects into the scene to check for intersections.
This particular algorithm requires that each ray develops in primitive space, and then is affinely transformed by the original object into world space, and then affinely transformed back into the primitive space of other objects in the scene to check for intersection.
Everything is fine until I make an anisotropic scale, for example, scaling an object by [2 2 1] (isotropic scales are beautiful). This makes me think that I am not correctly transforming the directional component of the beam. Currently, I am transforming the direction of the rays from primitive space to world space by multiplying the directional component by transposing the matrix of the inverse transformation of the source objects, and then converting the ray from world space to each primitive space by multiplying by transposing the transformation of the destination matrix objects.
I also tried to multiply the original primitive transformation matrix in order to move from primitive to world space and multiply by the recipient's inverse transformation in order to move from world space to primitive space, but this was unsuccessful.
I believe that a ray launched from the surface of a primitive object (at a random point and in a random direction) should be transformed in the same way as the surface normal in regular ray tracing, but I'm not sure.
Any of the experts know what the flaw in my methodology is? Feel free to ask if additional information is required.
The basic algorithm for this beam indicator is as follows:
For each object, i, in scene { for each ray, r, in number of rays per object { determine random ray from primitive i convert ray from primitive space of i to world space for each object, j, in scene { convert ray to primitive space of object j check for intersection with object j } } }
I hope that the issue becomes clear, let's look at an example. Suppose I have a cylinder that extends along the z axis (unit radius and height) and an annular space lying in the xy plane with an inner diameter of 7 and an outer diameter of 8. I want the cylinder scale to be 6 times in the x and y directions (but not in the z direction), so my affine transformation matrix looks like this:
M(cylinder) = |2 0 0 0| M^-1(cylinder) = | .5 0. 0. 0. | |0 2 0 0| | 0. .5 0. 0. | |0 0 1 0| | 0. 0. 1. 0. | |0 0 0 1| | 0. 0. 0. 1. | M(annulus) = |1 0 0 0| M^-1(annulus) = |1 0 0 0| |0 1 0 0| |0 1 0 0| |0 0 1 0| |0 0 1 0| |0 0 0 1| |0 0 0 1|
Suppose now that I have a ray that has a random starting point on the surface of the cylinder s and a random direction from the surface of the cylinder c giving the ray r (os) = s + ct.
I want to transform this ray from primitive space (object) to world space, and then check the intersection with other objects in the scene (ring space).
The first question is the correct way to convert the ray r (os) to world space, r (ws), using M (cylinder) or M ^ -1 (cylinder). The second question is how to properly convert the ray, r (ws), from world space to the space of objects, to check for intersection with other objects using M (ring space) and M ^ -1 (ring space),
Additional additional information:
This application is designed to calculate radiation heat transfer between N objects. A ray is launched from a random point of an object, and its direction is randomly selected within a hemispherical distribution oriented with a normal surface at a random point.
Here is some visualization of my problem. Direct ray distribution when it is first generated: 
If you apply the transformation to world coordinates using the transformation matrix M: 
If you apply the transformation to world coordinates using the inversion transformation matrix M ^ -1 