Presentation is loading. Please wait.

Presentation is loading. Please wait.

Advanced Computer Graphics Spring 2014

Similar presentations


Presentation on theme: "Advanced Computer Graphics Spring 2014"— Presentation transcript:

1 Advanced Computer Graphics Spring 2014
K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology

2 Today’s Topics Quaternions

3 Geometric Transformations
Rotation is defined by an axis and an angle of rotation. Rotation in 3D is not as simple as translation. It can be defined in many ways.

4 Two Rotational Modalities
Definition of Rotational Modality The combination of a definition and a corresponding mathematical representation Two popular modalities Rotation defined by Euler angles represented by general transformation matrices. Rotation defined by Euler’s theorem represented by quaternions.

5 Euler Angles The space of orientations can be parameterized by Euler angles. A general orientation is written as a series of rotations about three mutually orthogonal axes in space. Usually the x, y, and z axes in a Cartesian coordinate system are used. To describe a general rotation, three Euler angles are required, each of which is the rotation angles about the x, y, and z axes, respectively. The conversion from a general rotation to Euler angles is ambiguous. The same rotation can be obtained with different sets of Euler angles. The resulting rotation depends on the order in which the three rolls are performed.

6 Rotation Matrices Rotation matrices are the typical choice for implementing Euler angles. For each type of roll, there is a corresponding rotation matrix. The matrices rotate by multiplying them to the position vector for a point in space. The result is the position vector for the rotated point. A rotation matrix is a 3x3 matrix but usually homogeneous 4x4 matrices are used in computer graphics. Matrix multiplication is not generally commutative. It fits well with the fact that rotation in space do not commute.

7 Quaternions The second rotational modality is rotation defined by Euler’s theorem and implemented with quaternions. Euler’s rotational theorem An arbitrary rotation may be described by only three parameters.

8 Historical Backgrounds
Quaternions were invented by Sir William Rowan Hamilton in 1843. His aim was to generalize complex numbers to three dimensions. Numbers of the form a+ib+jc, where a,b,c are real numbers and i2=j2=-1. He never succeeded in making this generalization. It has later been proven that the set of three-dimensional numbers is not closed under multiplication. Four numbers are needed to describe a rotation followed by a scaling. One number describes the size of the scaling. One number describes the number of degrees to be rotated. Two numbers give the plane in which the vector should be rotated.

9 Basic Quaternion Mathematics
Quaternions, denoted q, consist of a scalar part s and a vector part v=(x,y,z). We will use the following form. Let i2=j2=k2=ijk=-1, ij=k and ji=-k. A quaternion q can be written: q = [s,v] = [s,(x,y,z)] = s+ix+jy+kz. The addition operator, +, is defined

10 Basic Quaternion Mathematics
Multiplication is defined: Quaternion multiplication is not generally commutative. Multiplication by a scalar is defined by rq ≡ [r,0]q Subtraction is defined q – q’ ≡ q + (-1)q’ Let q is a quaternion. Then q* is called the conjugate of q and is defined by q* ≡ [s,v]* ≡ [s, -v].

11 Basic Quaternion Mathematics
Let p,q quaternions. Then (q*)* = q, (pq)* = q*p*, (p+q)* = p* + q*, qq* = q*q The norm of a quaternion q. ||q|| = √qq* The inner product is defined q·q’ = ss’+v·v’ = ss’ + xx’ + yy’ + zz’ Let q,q’ quaternions. Define them as the corresponding four-dimensional vectors and let α be the angle between them. q·q’ = ||q|| ||q’|| cos α .

12 Basic Quaternion Mathematics
The unique neutral element under quaternion multiplication I = [1,0] Inverse under quaternion multiplication qq-1=q-1q=I. q-1=q*/||q||2

13 Basic Quaternion Mathematics
Unit quaternions If ||q|| = 1, then q is called a unit quaternion. Use H1 to denote the set of unit quaternions Let q = [s,v], a unit quaternion. Then, there exists v’ and θ such that q = [cosθ ,v’sinθ ]. Let q, q’ be unit quaternions. Then ||qq’|| = 1 q-1 = q* Etc…

14 Rotation with Quaternions
Let q=[cosθ,nsinθ] be a unit quaternion. Let r = (x,y,z) and p[0,r] be a quaternion. Then p’= qpq-1 is p rotated 2θ about the axis n. Any general three-dimensional rotation about n, |n|=1 can be obtained by a unit quaternion. Choose q such that q=[cosθ/2,nsinθ/2]

15 Rotation with Quaternions
Let q1, q2 be unit quaternions. Rotation by q1 followed by rotation by q2 is equivalent to rotation by q2q1. Geometric intuition

16 Comparison of Quaternions, Euler Angles and Matrices
Euler Angles/Matrices – Disadvantages Lack of intuition The order of rotation axes is important. Gimbal lock It is a concept originating from the air and space industry, where gyroscopes are used. At a certain situation, two rotations act about the same axis. Mathematically gimbal lock corresponds to loosing a degree of freedom in the general rotation matrix.

17 Comparison of Quaternions, Euler Angles and Matrices
Euler Angles/Matrices – Disadvantages Gimbal lock If we letβ=π/2, then a rotation with αwill have the same effect as applying the same rotation with -γ. The rotation only depends on the difference and therefore it has only one degree of freedom. For β=π/2 changes of α and γ result in rotations about the same axis.

18 Comparison of Quaternions, Euler Angles and Matrices
Euler Angles/Matrices – Disadvantages Implementing interpolation is difficult Ambiguous correspondence to rotations The result of composition is not apparent The representation is redundant Euler Angles/Matrices – Advantages The mathematics is well-known and that matrix applications are relatively easy to implement.

19 Comparison of Quaternions, Euler Angles and Matrices
Quaternions – Disadvantages Quaternions only represent rotation Quaternion mathematics appears complicated Quaternions – Advantages Obvious geometrical interpretation Coordinate system independency Simple interpolation methods Compact representation No gimbal lock Simple composition

20 Example Computation of Quaternion Rotation
Question: Rotate a vector (1,0,0) by -90o about (0,1,0). Solution??

21 Rotational Matrix vs. Unit Quaternion
The unit quaternion qR = [q0, q1, q2, q3]t represents rotation around the axis (q1,q2,q3). The rotation matrix R from the unit quaternion is given by

22 Interpolation of Solid Orientations
An application that benefits from a quaternion representation of rotation is keyframe animation. The rotational keyframes must be interpolated to produce reasonable in-between rotations. The quaternion representing the rotations can themselves be interpolated in a natural manner.

23 Interpolation of Solid Orientations
Visualization of interpolation curves Quaternion space is four-dimensional. Direct visualization is impossible. We always interpolate between unit quaternions. The interpolated quaternions will always be unit quaternions. We only need three dimensions to visualize the interpolated curves since they lie on the surface of the unit sphere.

24 Interpolation of Solid Orientations
Interpolation between two rotations Given an arbitrary set M we interpolate between x0∈M and x1∈M parameterized by h∈[0,1]. The resulting interpolation curve γ : MⅹMⅹ [0,1] -> M with γ(x0,x1,0)=x0, γ(x0,x1,1)=x1.

25 Interpolation of Solid Orientations
Linear Euler Interpolations Linear interpolation between two tuples of Euler angles between v0=(x0,y0,z0) and v1=(x1,y1,z1). LinEuler(v0,v1,h) = v0(1-h)+v1h. Not optimal and intuitively correct!!!

26 Interpolation of Solid Orientations
Linear Matrix Interpolations Linear interpolation between rotation matrices – Linear interpolation of every single matrix element independently of the others. LinMat(M0,M1,h) = M0(1-h) + M1h. In general this interpolation method does not produce orthonormal matrices -> Involve translation, scaling, projections etc. -> The interpolation can become wrong.

27 Interpolation of Solid Orientations
Linear Quaternion Interpolations Linear interpolation between rotation quaternions. Lerp(q0,q1,h) = q0(1-h)+q1h. The interpolation curve for linear interpolation gives a straight line in quaternion space. The angular velocity profile is not intuitively correct. Interpolated quaternions may not be unit quaternions.

28 Interpolation of Solid Orientations
Spherical Linear Quaternion Interpolations The same interpolation curve as Lerp method but the interpolation quaternions are unit quaternions. Great arc interpolation on the quaternion unit sphere.

29 Interpolation of Solid Orientations

30 3D Registration Problem Statement
Input: Two corresponded point sets, pi, xi, where i = 1,…,Np, and Np = Nx. Output: The optimal 3D rotation R and translation vector T so that is minimized.

31 3D Registration The centers of mass
The cross-covariance matrix of both points 4×4 matrix

32 3D Registration The unit eigenvector (quaternion) qR = [q0, q1, q2, q3]t corresponding to the maximum eigenvalue of the matrix Q(Σpx) is selected as the optimal rotation. The optimal translation vector is given by Rotation matrix R from a unit quaternion

33 3D Registration

34 3D Registration Before registration After registration

35 Virtual Trackball It allows the user to define 3D rotation using mouse in 2D windows. It works similarly like the hardware trackball devices

36 Virtual Trackball Superimpose a hemi-sphere onto the viewport.
This hemi-sphere is projected to a circle inscribed to the viewport. The mouse position in 2D space is projected orthographically to this hemi-sphere.

37 Virtual Trackball Keep track the previous mouse position and the current position. Calculate their projection positions P1 and P2 to the virtual hemi-sphere. We then rotate the sphere from P1 to P2 by finding the proper rotation axis and angle. This rotation is then applied to the object. You should also remember to accumulate the current rotation to the previous modelview matrix.

38 Virtual Trackball The axis of rotation is given by the normal to the plane determined by the origin, p1 and p2. The angle between p1 and p2 is given by n = p1  p2 | sin q| =

39 Virtual Trackball How to calculate P1 and P2?
Assuming the mouse position is (x,z), then the sphere point P also has x and z coordinates equal to x and z. Assume the radius of the hemi-sphere is 1. So the y coordinate of P is If a point is outside the circle, project it to the nearest point on the circle. (set y to 0 and renormalize (x,z))

40 Virtual Trackball Visualization of the algorithm


Download ppt "Advanced Computer Graphics Spring 2014"

Similar presentations


Ads by Google