21
Preserving Normals Lecture 28 Wed, Nov 12, 2003

Preserving Normals

  • Upload
    toshi

  • View
    51

  • Download
    0

Embed Size (px)

DESCRIPTION

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. - PowerPoint PPT Presentation

Citation preview

Page 1: Preserving Normals

Preserving Normals

Lecture 28Wed, Nov 12, 2003

Page 2: Preserving Normals

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?

Page 3: Preserving Normals

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

Page 4: Preserving Normals

Rotations, Translations, and Scalings

However, under scalings, their images will, in general, not be orthogonal.

v nv n

Page 5: Preserving Normals

Rotations, Translations, and Scalings

Nor will they be orthogonal under a shear transformation.

v n v n

Page 6: Preserving Normals

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

Page 7: Preserving Normals

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.

Page 8: Preserving Normals

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. (?)

Page 9: Preserving Normals

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.

Page 10: Preserving Normals

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.

Page 11: Preserving Normals

The Case of Translations

The case of translations is very simple since the matrix does not change the normal vector in the first place.

1 0 0 dx

0 1 0 dy

0 0 1 dz

0 0 0 1

vx

vy

vz

0

vx

vy

vz

0

=

Page 12: Preserving Normals

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.

Page 13: Preserving Normals

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.

Page 14: Preserving Normals

Scalings

Let M be the matrix of the scaling Scale(sx, sy, sz).

Then

sx 0 0

0 sy 0

0 0 sz

M =

1/sx 0 0

0 1/sy 0

0 0 1/sz

(M-1)T =

Page 15: Preserving Normals

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 vectorn’ = (M-1)Tn = (nx/sx, ny/sy, nz/sz).

Page 16: Preserving Normals

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.

Page 17: Preserving Normals

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.

Page 18: Preserving Normals

Consequences for Programming

However, In translations, it is not necessary to

do anything. In rotations, we may apply the very

same matrix.

Page 19: Preserving Normals

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.

Page 20: Preserving Normals

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.

Page 21: Preserving Normals

Example: Scaling in the Mesh Class

NormScaler.cppmesh2.cppvector3.cpp