Search code examples
matrixgeometrylinear-algebraraytracing

Intersection between a line and an object, which was transformed by a matrix


For a C++ ray tracing project, I have a 3D object, which is described by an equation. This object can be transformed by a 4x4 matrix M (which itself can be a rotation/translation/scale matrix, or a combination of any of those matrices).

Now, I want to compute the point(s) of intersection (if they exist) between this modified object and a line, of known origin and vector.

What is the most appropriate way to compute these points (given that I can compute the intersections between any non-transformed object and a line) ?

Can I simply apply M-1 to the line's origin and vector (to transform the line into the object's local coordinates), and then compute the intersection between this modified line and the object, or is there some functional/more efficient work-around that I can set up ?


Solution

  • Yes,

    inverse affine transformation of line
    intersection calculation
    then forward affine tranformation of intersection points
    

    usually is the best way (except for cases when transformed equation is as simple as initial one)