Advertisement

Transforming normals and vectors

Started by October 15, 2001 03:49 PM
0 comments, last by kamrann 23 years, 3 months ago
I''ve always been uncertain about the differences between transforming points, vectors and normals. I hope someone can tell me if I now have it sorted. I am using 4x4 matrices in all cases. I know that when transforming a vector, I dont want to include any translation. If I''m transforming a polygon by a non-uniform scaling matrix, then am I right in thinking that I in fact have to transform the normal by the inverse of the matrix? Another thing that I''m not sure on is, if I have a matrix built up by an arbitrary combination of translations, rotations and scales, and I want to use it to transform the orientation of a vector, is it right to simply set the translation part of the matrix to 0? Also, this one confuses me: if a have a matrix which translates -10 along x, then scales x by 2.0, then translates back +10 along x, and apply this to a point, should the point come out as it started, or should its x component be less than when it started, which is what I''m getting? Finally, sorry about all the questions, but I just wanted to know if this function will work properly - it includes basically a bit of all the above. To transform a plane by a Matrix M which could be any combination of translations, rotations and scalings: Plane TransformPlane(const Plane& plane, const Matrix& M) { Plane result; Vector point_in_plane = plane.normal * plane.distance; point_in_plane = M * point_in_plane; Matrix M2 = M; Set translation part of M2 to zero. M2 = M2.Inverse().Transpose(); result.normal = M2 * plane.normal; result.normal.Normalize(); result.distance = Dot(result.normal, point_in_plane); return result; } thanks to anyone who can bear to read through all that. Cameron
Since rotations and translations preserve angles they can be ignored. If two vectors are orthogonal then their dot product is zero. If you have non-uniform scaling factors of a, b and c then the inverse is 1/a, 1/b and 1/c. If you have two vectors (s,t,u) and (x,y,z) then multiplying one by the matrix and the other by the inverse gives (a*s, b*t, c*u) and the other (x/a, y/b, z/c). The dot product of the two vectors is s*x+t*y+u*z or the dot product of the original two vectors. So if they where orthongonal to start with they will still be orthogonal. I''m not sure on the second one. It would seem reasonable. The last part isn''t true because the translation of -10 becomes -20 after scaling and then you are moving it back by only 10 or half way. You would have to scale the translation vector to get it back to where it was.
Keys to success: Ability, ambition and opportunity.

This topic is closed to new replies.

Advertisement