I'm writing a program that calculates the intersection of a ray with a sphere S that is transformed by a 4x4 matrix M. The ray's parametric equation is as follows (o = origin vector, d = direction vector): r(t) = o + dt. To find the intersection with the sphere, I will apply the inverse of M (M') on the ray and calculate the intersection of M'r(t) with S. M'r(t) = M'o + M'dt

Let r1(t) = [0,0,0] + t[0,0,-1]

Here's where I'm confused: If M translates 2 units in the negative z plane, then then r2(2) = M'o + M'dt = [0,0,2] + t[0,0,1] will result in a ray that points in the opposite direction of S.

The way I see it I should apply translation transformations only to the rays origin but my lecture notes state otherwise. What am I not understanding? Lecture note exerpt:

For a pixel $p(x,y)$, we form a parametric equation for the ray as: $$ \vec{R}(t)=\vec{e}+\vec{c}t $$ where $\vec{e}=(0,0,-d)$ and $\vec{c}=(x,y,0)-\vec{e}$. The vector $(x,y,d)$ is thus in the direction of the ray. If we create and instance of a generic object and place it where we cant it in the scene, then there exits a transformation matrix $M$ that performs this operation: $$ \vec{q}=M\vec{q}' $$ where $\vec q$ is the generic object transformed as we desire it to appear in the scene. At this point, we need to find out if the ray for a given pixel intersects this object. An efficient way of performing this computation is to keep the object in its generic form $\vec q'$ and apply the inverse transformation $M^{-1}$ to the ray $\vec R(t)$ instead. The transformed ray can thus be written in the following way: $$ \vec R(t)M^{-1}=M^{-1}(\vec e+\vec ct)=M^{-1}\vec e+M^{-1}\vec ct $$ Conveniently, the values for $t$ at intersections are the same in both spaces.


Translating a vector doesn't make sense, because a vector doesn't have a position; only translation of points makes sense.

The usual way to handle this in computer graphics is as follows: when you "lift" 3D points and vectors into 4D, you use $w=1$ as the 4th coordinate of a point, but you use $w=0$ as the 4th component of a vector. Then, when you multiply a vector by a $4 \times 4$ matrix, you end up multiplying the "translation" elements of the matrix by zero, so no translation gets applied to the vector.

| cite | improve this answer | |
  • $\begingroup$ I knew I was missing something simple. Thanks for answering; this program is due tomorrow $\endgroup$ – Mark McKenna Dec 5 '13 at 19:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.