1 / 21

Preserving Normals

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? A translation? A rotation? A scaling? Other?. v. n. v. n. Rotations and Translations.

toshi
Download Presentation

Preserving Normals

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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. v n v n 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.

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

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

  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. n v

  7. The Effect on a Normal • Then n  v = 0. • Equivalently, if we regard n and v as 3  1 matrices, then nTv = 0, where nT 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’)Tv’ = (Mn)T(Mv) = (nTMT)(Mv) = nT(MTM)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)Tn. • Then n’’Tv’ is (n’’)Tv’ = ((M-1)Tn)T(Mv) = (nTM-1)(Mv) = nT(M-1M)v = nTv = 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. =

  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) = nTv = 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 = MT.) • Such a matrix is said to be orthonormal. • Therefore, (Mn)T(Mv) = (nTMT)Mv = nT(MTM)v = nT(I)v = nTv = 0.

  14. Scalings • Let M be the matrix of the scaling Scale(sx, sy, sz). • Then (M-1)T = M =

  15. Scalings • Under the scaling Scale(sx, sy, sz), the point P = (x, y, z) is transformed into the point P’ = MP = (sxx, syy, szz). • But the normal vector n = (nx, ny, nz) must be transformed into the normal vector n’ = (M-1)Tn = (nx/sx, ny/sy, nz/sz).

  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

More Related