Download presentation
Presentation is loading. Please wait.
Published byWilfrid Greene Modified over 9 years ago
1
CS 450: COMPUTER GRAPHICS 3D TRANSFORMATIONS SPRING 2015 DR. MICHAEL J. REALE
2
INTRODUCTION So far, we’ve covered 2D transformations Now we will cover 3D transformations Since we’re using homogeneous coordinates, we will use 4x4 matrices Overview: Translation, Scaling, and Shear Transforming to/from Another Basis Rotation Around the Standard Axes Around an Arbitrary Axis Using Euler Transform Normal transform
3
AFFINE TRANSFORMS Affine transform = linear transformation followed by a translation Parallel lines stay parallel after an affine transform Does NOT necessarily preserve lengths and angles Has form: All translation, rotation, scaling, reflection, and shearing matrices are affine
4
TRANSLATION, SCALING, AND SHEAR
5
3D TRANSLATION The 3D translation matrix isn’t that far removed from the 2D variation: Example: move point 5 units in x, -7 units in y, and 3 units in z:
6
3D SCALING The 3D scaling matrix too is very similar (it also only scales along the standard axes): Example: make something twice as large in the z direction:
7
3D SHEAR The 3D shear matrices are a little more complicated Six basic shear matrices all shear in planes orthogonal to the standard axes Example: shear in x direction based on value of z: Shear matrices preserve volume (determinant equals 1)
8
TRANSFORMING TO/FROM ANOTHER BASIS
9
CHANGING TO A NEW ORTHONORMAL BASIS IN 3D Assuming our basis (r, s, t) is orthonormal, we can change from the standard basis to the new basis with: The 4x4 homogeneous matrix would be:
10
CHANGING BACK TO THE STANDARD BASIS 3D To change BACK to the standard basis, remember that M is orthogonal (because ultimately it is a rotation matrix): The 4x4 homogeneous matrix would be:
11
ROTATION IN 3D: INTRODUCTION
12
3D ROTATION Rotation in 3D can be specified a number of ways: Around the standard axes about the x, y, and z axes Around an arbitrary axes will involve a composite transform with a change of base Using Euler angles using pitch, yaw, and roll angles Using Quaternions Remember: all rotation matrices are orthogonal R -1 (θ) = R T (θ) = R(-θ)
13
ROTATION AROUND THE STANDARD AXES
14
3D ROTATION AROUND STANDARD AXES R x (θ) rotation about x axis: R y (θ) rotation about y axis: R z (θ) rotation about z axis: Extended version of 2D rotation, since in 2D we are effectively ALWAYS rotating around the z axis
15
ROTATION AROUND AN ARBITRARY AXIS
16
3D ROTATION AROUND ARBITRARY AXIS Given an axis r we want to rotate around: Find two other vectors s and t to form an orthonormal basis: Transform into that basis Rotation about x axis (equivalent to r) Transform back to standard basis
17
ALL YOUR BASIS ARE BELONG TO US Normalize r (if it isn’t already) Find temporary s find smallest component of r and set it to zero, swap two remaining components and negate one of them (numerically stable): Normalize s: Compute t using cross product: r = “x axis” s = “y axis” t = “z axis” Note: s will be orthogonal to r. For example, if r x was the smallest element of r: Note: t will be orthogonal to r and s
18
BASIS CHANGE, ROTATE, AND THEN BACK AGAIN Recall the matrix for doing a basis change (and undoing it): So, our complete rotation matrix X will be:
19
ROTATION ABOUT AN ARBITRARY AXIS
20
ROTATION USING EULER TRANSFORM
21
EULER TRANSFORM Euler Transform Named after the great Swiss mathematician Leonhard Euler (1707-1783) Intuitively camera like your head (or jet plane) LOTS of different ways to formulate this, but all concatenation of rotations One common approach: y axis then x axis then z axis: Angle around y axis h “yaw” (or “head”) Angle around x axis p “pitch” Angle around z axis r “roll” Note: roll going in wrong direction in figure
22
INVERSE OF EULER TRANSFORM Euler transform all rotations orthogonal matrix! …or you can just get E T directly Recall:
23
PROBLEM: GIMBAL LOCK Degrees of freedom (DOF) = how many variables you need to describe movement Train on track one degree of freedom = how far along track it is Object in space 3 translation + 3 rotation = 6 degrees of freedom! Gimbal lock = when rotations are made such that we lose a degree of freedom Example: using y / x / z ordering set pitch (x axis rotation) to 90° (or π/2 radians) y axis in line with z axis! Only dependent on one angle (r+h)
24
ORDER OF ROTATIONS There are 24 different kinds of rotation orders one can use for the Euler transform: z / x / y animation z / x / z animation and physics Only get gimbal lock with 180° rotation around x Unfortunately, NONE of them eliminate the possibility of gimbal lock
25
PROS AND CONS OF EULER TRANSFORM Pros: Intuitive E.g., nod head “yes” change pitch up and down Useful for small angle changes or view orientation Cons: Gimbal lock Interpolation between two different sets of Euler angles nontrivial Cannot just interpolate each angle Two different sets of Euler angles can give SAME final rotation! For these reasons, we will explore quaternions instead…
26
GETTING EULER ANGLES FROM AN ORTHOGONAL MATRIX If you have an orthogonal matrix F, you can get the Euler angles like this: Problems: If f 01 = f 11 = 0 can’t use arctan however, can use simplified version of F If p outside internal of arcsin (+-90°), cannot get p In general, (h,p,r) are not unique! Above approach can be numerically unstable
27
NORMAL TRANSFORM
28
TRANSFORMING THE NORMAL There are cases wherein, if we blindly apply a transformation to the surface normal, it will not give us the right answer
29
GENERAL CASE Given a transform M, the normal should be multiplied by the transpose of the matrix’s adjoint: Normal may have to be renormalized afterwards Can also use transpose of the inverse; however: Can be overkill Inverse may not exist; adjoint ALWAYS exists Recall:
30
SIMPLIFYING CASES Expensive to compute 4x4 adjoint Translation will not affect normal (just a direction, not a point) If transformation is affine just get adjoint of upper-left 3x3 submatrix Just need this part if transform is affine:
31
MORE SIMPLIFYING CASES If transform only translations, rotations, UNIFORM scaling Translation no effect UNIFORM scaling only affects length of normal (we will renormalize anyway) Rotations transpose = inverse so transpose of inverse transpose of transpose original matrix! So, can use original transformation! If transform only translations and rotations Don’t need to renormalize!
32
WHEN YOU DON’T NEED TO WORRY ABOUT THIS Note: If you’re just recomputing the normal for each triangle after transformation, then obviously this isn’t an issue Also note: tangent vectors can just be transformed with everything else (they don’t need special treatment)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.