   Inverse Transform
  Hi. I am trying to do ray / box intersection. Location of box is not at origin.object render matrix is |  0.5  0.5  0.0||- 0.5  0.5  0.0||- 6.0  4.0  1.0|and ray start and end values arerayStart = [ -10, -2.5, 0.0], rayEnd = [ -3, 7, 0].the collision matrix for object is at origin i-e|1.0    0.0   0.0||0.0    1.0   0.0||0.0    0.0   1.0|now how can I intersection test with this box. I think I have to apply inverse transform to rayStart and rayEnd.Inverse of object render matrix is = objInverse|1.0   -1.0    0.0||1.0    1.0    0.0||2.0   -10.0   1.0|and multiplying rayStart and rayEnd with objInverse is objInverse*rayStart = [ -7.5, -12.5, 5.0 ]objInverse*RayEnd = [ -10, 4.0, -76 ]and these values dont look right.Can some one please tell me how to get it correct.Any help will be appreciated.RegardsKazz   
  To make life easier, please tell us which kind of vectors you use (column or row vectors) and whether you are dealing with 2 or 3 space dimensions.If you're dealing with 3 dimensions, then the origin of the box is not told to us. So computing the resulting "inverse" ray is not completely traceable for us.If you're dealing with 2 dimensions (so that the vectors shown are homogeneous ones), then at least the "rayStart" cannot be correct (it would be a direction vector, but has to be a position vector).From what I would assume due to the shown numbers, I think you're dealing with 2 dimensions, use row vectors, and use homogeneous vectors. (In this case, as said, is your rayStart incorrect.) However, the matrix product used in the OP shows column vectors... Please clarify these issues for furthur help.EDIT: The numerical part of the matrix product seems to work correctly.   ;  Hi. Thanks for answer and sorry for confusion. I am talking about row major and 2D. so by object render matrix| 0.5 0.5  0.0| == > x axis|- 0.5 0.5 0.0| == > y axis|- 6.0 4.0 1.0| ==> posi meanobject pos = [ -6.0, 4.0, 1.0]and its axis are x axis  = [ 0.5, 0.5, 0.0 ]y axis = [ -0.5, 0.5, 0.0 ]For ray start, how can that be incorrect. please have a look at the picture here http://i44.tinypic.com/xf6ntc.jpg just to be more clear.Thankyou Kazz;Quote:I am talking about row major...That's actually not what 'row major' means. What you mean is that the matrix has been built for use with row vectors. (Which does answer haegarr's question, just with the wrong terminology.)   ;  First on, "row/column major order" defines the way how the 2 dimensions of a matrix are linearized, e.g. to be stored in computer memory. On the other hand, "row/column vector" defines, roughly spoken, whether you multiply matrix by vector or else vector by matrix. (Edit: In the meanwhile jyk has already told that, but I leave my comment here.)You have defined to use row vectors, but you matrix-vector product is for column vectors. So you have to computerayStart * objInverserayEnd * objInverseinstead ofobjInverse*rayStartobjInverse*rayEndThis is important because matrix multiplication is not commutative.Your other problem is this: Homogeneous vectors have a homogeneous co-ordinate. This co-ordinate is 0 (zero) for direction vectors and not 0 for position vectors. It is especially 1 for position vectors if normalized. Now, look at your object matrix: The object's position has a 1 and the axes (which are direction vectors) have a 0, so they are correct. You ray has a position (rayStart) and another position (rayEnd), both showing a homogeneous co-ordinate of 0. That is wrong. Since both vectors denote a position, their homogeneous co-ordinates have to be 1!This is because: If the homogeneous co-ordinate is 0, then the translational part of a transformation matrix has no effect on the vector. If it is 1 (or "differs from 0" in general) then the translation _has_ an effect. Logically you can say that a translational transformation has an effect on positions but not on directions. Please remember this because it will help you in many such situations.You can also think of rules derived from that, E.g.position - position =: directiondue to( x1 y1 1) - (x2 y2 1) = (x1-x2 y1-y2 0)so that the difference between 2 positions is a direction. Other such rules can be derived, too.I assume the both issues explained above will solve your problem.   ;  I have changed the ray start and end to ray start = [- 10.0,- 2.5,1.0]ray end = [- 3.0,7.0,1.0]thenrayStart * invObj = [- 10.5,- 2.5,1.0]rayEnd * invObj =  [6.0,0.0,1.0]where invObj matrix is1.0  -1.0    0.01.0   1.0    0.02.0  -10.0   1.0again this does not looks right as magnidute for ray has changed from 11.80 to 16.68.I have posted pic here what it looks right nowhttp://i43.tinypic.com/eueu07.jpg.RegardsKazz ;  First, you can see that the 2 normalized positions of the ray are transformed into 2 other normalized positions. That is a good thing.Second, of course the magnitude has changed. Look at the object's matrix. The upper left 2 by 2 sub-matrix defines the rotation _and_ scaling part. As you can see, the magnitude of each row vector is not 1, becausesqrt( 0.52 + 0.52 ) == 0.707 != 1sqrt( (-0.5)2 + 0.52 ) == 0.707 != 1Hence there is not only a rotation but also a scaling (a uniform scaling, to be precise). The inverse scaling factor is1 / 0.707 == 1.414and look what the magnitude of the ray's direction vectors does:16.68 / 11.80 == 1.414Voila, mathematically its all okay. Its just so that your object matrix scales the space. If you don't want to incorporate scaling, then choose row vectors that have a magnitude of 1. If you would construct matrices by invoking rotation routines, you would see that resulting matrices will ever have this feature (besides numerical inaccuracies, of course).Edit: The magnitude of 1 is not the only feature of pure rotation matrices. There is also the necessity of pairwise orthogonality. So please don't pick some arbitrary numers that fit only the first of both features. Better is you actually use the sin/cos functions to compute rotation matrices.   ;  Lovely mate. That was accurate result.I preasume that we need to do exactly in 3d, ( or do we need any additional steps  ??? ).Thanks once again for all the help.RegardsKazz   ;Quote:Original post by sfx81I preasume that we need to do exactly in 3d, ( or do we need any additional steps  ??? ).You're right: These things work in 3D, too.