Presentation is loading. Please wait.

Presentation is loading. Please wait.

Geometric Objects and Transformations (II)

Similar presentations


Presentation on theme: "Geometric Objects and Transformations (II)"— Presentation transcript:

1 Geometric Objects and Transformations (II)
姜明 北京大学数学科学学院 Based on [EA], Chapter 4. 更新时间2019年2月24日星期日11时33分58秒

2 Outline Affine Transformations Translation, Rotation, and Scaling
OpenGL Transformation Matrices Interfaces to Three-Dimensional Applications Quaternions and Rotation

3 Affine Transformations
A transformation is a function that takes a point (or vector) and maps that point (vector) to another point (or vector). This formulation is too general to be useful. In practice, we would have to carry out the transformation on every point. E.g., to transform a line segment, a general transformation might requires to carry out the transformation for every point between the two end points. Instead, we consider a restricted class of transformations. Linear functions/transformations: The importance of this kind of transformations is that, if we know the transformations of vertices, we can obtain the transformations of linear combinations of vertices by linear combinations of transformations of the vertices. We do not have to calculate the transformations of every point.

4 In 4D space, a linear transformation can be represented as matrix multiplication
Each linear transformation corresponds to a change in frame, as long as it is non-singular. 4x4 matrix that leaves unchanged the 4th component of a representation, 12 degree of freedom.

5 Transformation of Lines
Suppose that we write a line in the form For any affine transform Thus, we can construct the transformed line by first transforming the start point and directional vector, and using whatever line-generation algorithm for rendering the line.

6 The importance of the above result in computer graphics is practical.
For line segments, we need only to transform the homogeneous coordinate representation of the end points of a line segment to determine completely a transformed line. Thus, we can implement our graphics systems as a pipeline that passes endpoints through affine transformation units, and we can generate the line at the rasterization stage.

7 Translation Translation is defined by a displacement vector.
It has 3 degree of freedom. is called the translation matrix.

8 Scaling It is an affine non-rigid-body transformation.
There are uniform and non-uniform scalings. It has a fixed point. It has 3 degree of freedom in addition to the fixed point. is called the scaling matrix.

9 Shear It pulls the top to the right and bottom to the left.
Y- and Z- values are not changed. This is called the X shear. is called the shear matrix.

10 2D Rotation

11 3D Rotation about Axes 2D Rotation is equivalent to 3D rotation about the Z-axis. Rotation matrices about X- and Y- axes. The negative sign of the sine term in the last matrix is consistent with our definition of a positive rotation in a right-handed system: it is counterclockwise when we look down the positive axis toward the origin.

12 Rotation about a Fixed Point
y z x y z

13 Sequence of Transformations
x y z x y z Translation Translation x y z x y z Rotation

14 General Rotation about the Origin
An arbitrary rotation about the origin can be composed of 3 successive rotations about the 3 axes. We can form the desired matrix by doing first a rotation about the Z-axis, then a rotation about the Y-axis, and concluding with a rotation about the X-axis.

15 Rotation about an Arbitrary Axis
Given A fixed point, P0, the center of the cube. A vector to rotate about, u. An angle of rotation, θ. Find the transformation matrix. The vector u can be specified by two points: u = P2 – P1.

16 Replace u with a unit length vector v with the same direction.
Move the fixed point to the origin. Our first matrix is T(-P0). Our final one is T(P0).

17 Carry out two rotations to align the axis of rotation, v, with the z-axis. First onto the plane y = 0, then onto the plane x = 0. Then, rotate by θ about the z-axis. The final matrix is

18 The difficult part is determining θx and θy.
The directional cosines

19 The effect of the desired rotation on the point α is to rotate the line segment into the plane y = 0.

20 The geometry is changed after Rx is applied.
Note that the angle is clockwise about the y-axis. We have to be careful of the sign of the sine terms in the matrix.

21 OpenGL Transformation Matrices
The Current Transformation Matrix Order of Transformations Rotation, Translation, and Scaling Rotation About a Fixed Point in OpenGL Loading, Pushing, and Popping Matrices

22 The Current Transformation Matrix
The generalization common to most graphics systems is the current transformation matrix (CTM). It is applied to any vertex that is defined subsequent to its setting. If we change the CTM, we change the state of the system. The functions that alter CTM are of two forms: Those that reset it to some matrix: C←M. Those that modify it by post-multiplication (or pre-multiplication) by a matrix: C←CM.

23 Matrix Mode in OpenGL Load Matrix Matrix Mode 3D Model Vertices Stack
Current Stack Current 2D 3D Vertices Modelview CTM Projection

24 Order of Transformations
In OpenGL, the transformation specified last is the one applied first. The is a consequence of post-multiplication. Altering the CTM is similar to pushing matrices onto a stack. first in last out.

25 Rotation, Translation and Scaling
glTranslatef (dx, dy, dz); Multiplies current matrix with translation matrix. dx, dy, and dz are translations along x,y, and z axes. glRotatef (angle, x, y, z); Multiplies current matrix with rotation about the line from the origin through the point (x, y, z) by angle. Right hand rule applies. glScalef (sx, sy, sz); Multiplies current matrix with scaling matrix. sx, sy, sz are the scale factors along the x, y, and z axes.

26 Rotation about a Fixed Point
glMatrixMode (GL_MODEL_VIEW); glLoadIdentity (); glTranslatef (4., 5., 6.); glRotatef (45., 1., 2., 3.); glTranslatef (-4., -5., -6.); 45-degree rotation about the line through origin and the point (1,2,3) with a fixed point (4,5,6). Note the order of translations applied.

27 Loading, Pushing and Popping matrices
glLoadIdentity (); Loads an identity matrix onto the top of the current stack glLoadMatrixf (pointer_to_matrix); Loads arbitrary matrix onto top of the current stack glMultMatrixf (pointer_to_matrix); Postmultiplies current matrix by arbitrary matrix Matricies are one-dimensional arrays of type GLfloat in column major order.

28 Quaternions Complex Numbers and Quaternions Quaternions and Rotation

29 Complex Numbers and Quaternions
Rotation by complex numbers Quaternions

30 Operations

31

32 Quaternions and Rotation
The rotation with an angle θ about a vector v=(a,b,c) can be implemented with quaternions. For an arbitrary point p=(x,y,z).

33 Mathematica Script for the above derivation (pdf copy)
It can be proved For the matrix constructed earlier it can be shown that Mathematica Script for the above derivation (pdf copy)

34 Quaternions are faster and have been built into both hardware and software implementations.
In addition to the efficiency, quaternions can be interpolated to obtain smooth sequences of rotations for animation.

35 Gimbal Lock Do We Really Need Quaternions?
Why Diana Gruber's wrong about Quats Performance of quaternions in the GPU 万向节死锁(Gimbal Lock)问题


Download ppt "Geometric Objects and Transformations (II)"

Similar presentations


Ads by Google