Presentation is loading. Please wait.

Presentation is loading. Please wait.

Preserving Normals Lecture 28 Wed, Nov 12, 2003. The Effect of a Transformation on a Normal What happens to a normal vector under a linear transformation?

Similar presentations


Presentation on theme: "Preserving Normals Lecture 28 Wed, Nov 12, 2003. The Effect of a Transformation on a Normal What happens to a normal vector under a linear transformation?"— Presentation transcript:

1 Preserving Normals Lecture 28 Wed, Nov 12, 2003

2 The Effect of a Transformation on a Normal What happens to a normal vector under a linear transformation? A translation? A rotation? A scaling? Other?

3 Rotations and Translations It seems intuitive that if u and v are orthogonal, then their images will be orthogonal under both translations and rotations, since these are rigid motions. v n v n

4 Rotations, Translations, and Scalings However, under scalings, their images will, in general, not be orthogonal. v n v n

5 Rotations, Translations, and Scalings Nor will they be orthogonal under a shear transformation. v n vn

6 The Effect on a Normal Let v be a vector lying in the tangent plane. Let n be a unit normal vector at that point. v n

7 The Effect on a Normal Then n  v = 0. Equivalently, if we regard n and v as 3  1 matrices, then n T v = 0, where n T is the transpose of n and the operation is matrix multiplication.

8 The Effect on a Normal Let M be a linear transformation. Then M maps v to v’ = Mv and M maps n to n’ = Mn. In general, v’ and n’ will not be orthogonal. That is because (n’) T v’ = (Mn) T (Mv) = (n T M T )(Mv) = n T (M T M)v  0. (?)

9 Transforming a Normal So if Mn is not orthogonal to v’, then what vector will be orthogonal to v’? Let’s try n’’ = (M -1 ) T n. Then n’’ T v’ is (n’’) T v’ = ((M -1 ) T n) T (Mv) = (n T M -1 )(Mv) = n T (M -1 M)v = n T v = 0.

10 Transforming a Normal This demonstrates that if the surface points are transformed by matrix M, then the surface normals should be transformed by the matrix (M -1 ) T, the transpose of the inverse, in order to remain normal to the surface.

11 The Case of Translations The case of translations is very simple since the matrix does not change the normal vector in the first place. 100dx 010dy 001dz 0001 vxvx vyvy vzvz 0 vxvx vyvy vzvz 0 =

12 The Case of Translations In the case of translations, we know that Mn = n and Mv = v. It follows that Mn and Mv are orthogonal since (Mn) T (Mv) = n T v = 0.

13 The Case of Rotations In the case of rotations, the transpose of the inverse of the matrix is the same matrix again! (I.e., M -1 = M T.) Such a matrix is said to be orthonormal. Therefore, (Mn) T (Mv) = (n T M T )Mv = n T (M T M)v = n T (I)v = n T v = 0.

14 Scalings Let M be the matrix of the scaling Scale(s x, s y, s z ). Then sxsx 00 0sysy 0 00szsz M = 1/s x 00 01/s y 0 001/s z (M -1 ) T =

15 Scalings Under the scaling Scale(s x, s y, s z ), the point P = (x, y, z) is transformed into the point P’ = MP = (s x x, s y y, s z z). But the normal vector n = (n x, n y, n z ) must be transformed into the normal vector n’ = (M -1 ) T n = (n x /s x, n y /s y, n z /s z ).

16 Other Transformations For other transformations, we must apply the transpose of the inverse matrix to the normal vectors to produce normals to the transformed surface.

17 Consequences for Programming OpenGL applies transformation matrices to both the vertices but it applies the transpose of the inverse to the normals. One consequence is that, if we compute the transformed normals ourselves, then we must be sure to apply the transpose of the inverse and renormalize.

18 Consequences for Programming However, In translations, it is not necessary to do anything. In rotations, we may apply the very same matrix.

19 Renormalizing Vectors in OpenGL Luckily, OpenGL will automatically recalculate normals if we ask it to. We should write the statement glEnable(GL_NORMALIZE); This statement forces OpenGL to renormalize all surface normals after transformations, throughout the program.

20 Caution This function call is expensive since unit normals have already been computed and now they must be recomputed. It should be used only if the transformations include scalings or non- standard transformations. It would be more efficient to compute the correct normals from the start, if the situation allows for that.

21 Example: Scaling in the Mesh Class NormScaler.cpp mesh2.cpp vector3.cpp


Download ppt "Preserving Normals Lecture 28 Wed, Nov 12, 2003. The Effect of a Transformation on a Normal What happens to a normal vector under a linear transformation?"

Similar presentations


Ads by Google