Chapter 7 Geometric Transformation 1 Objectives F To
Chapter 7 Geometric Transformation 1
Objectives F To describe transformations related to 3 D graphics F To construct 3 D affine transforms including translation, rotation, scaling, shearing, and reflections F To understand apply transformation matrices F To apply transforms in scene graphs F To construct and apply composite transformations F To apply transforms in constructing geometries 2
Affine Transformation 3 D affine transformation In homogeneous coordinates 3
Matrix Classes Matrix 3 f Matrix 3 d Matrix 4 f Matrix 4 d GMatrix Source void add(Matrix 4 d m 1) void sub(Matrix 4 d m 1) void mul(Matrix 4 d m 1) void invert() void add(Matrix 4 d m 1, Matrix 4 d m 2) void sub(Matrix 4 d m 1, Matrix 4 d m 2) void mul(Matrix 4 d m 1, Matrix 4 d m 2) void invert(Matrix 4 d m 1) void transpose() void mul(double scalar) double determinant() Run 4
Transform 3 D Class Translation void set(Vector 3 d trans) set(Vector 3 f trans) set. Translation(Vector 3 d trans) set. Translation(Vector 3 f trans) Scale void set(double scale) void set. Scale(Vector 3 d scales) 5
Reflection and Shear Reflection Shear 6
3 D Rotation About z-axis Set a general rotation in Transform 3 D void set(Axis. Angle 4 d r) 7
Quaternion and 3 D Rotation A point represented as a pure quaternion A rotation defined by quaternion operations θ is the angle of rotation and u defines the axis of rotation through the origin 8
Euler Angles F Use three rotations about the coordinate axes F Different Names: – (elevation, azimuth, tilt) – (roll, pitch, yaw) – (precession, nutation, spin) – (heading, altitude, bank) F Transform 3 D method void set. Euler(Vector 3 d euler. Angles) 9
Quaternion to Euler Angle Conversion public static Vector 3 d quat. To. Euler(Quat 4 d q 1) { double sqw = q 1. w*q 1. w; double sqx = q 1. x*q 1. x; double sqy = q 1. y*q 1. y; double sqz = q 1. z*q 1. z; double heading = Math. atan 2(2. 0 * (q 1. x*q 1. y + q 1. z*q 1. w), (sqx - sqy - sqz + sqw)); double bank = Math. atan 2(2. 0 * (q 1. y*q 1. z + q 1. x*q 1. w), (-sqx - sqy + sqz + sqw)); double attitude = Math. asin(-2. 0 * (q 1. x*q 1. z q 1. y*q 1. w)); return new Vector 3 d(bank, attitude, heading); } Source Run 10
Transform. Group Node Source Run 11
Composite Transforms A useful pattern Source Run 12
Transform 3 D methods void void void transform(Point 3 d p) transform(Point 3 d p, Point 3 d p. Out) transform(Point 3 f p, Point 3 f p. Out) transform(Vector 3 d v, Vector 3 d v. Out) transform(Vector 3 f v, Vector 3 f v. Out) transform(Vector 4 d v, Vector 4 d v. Out) transform(Vector 4 f v, Vector 4 f v. Out) 13
Shape Construction Extrusion: Extend a 2 D shape to 3 D Source Rotation: For example, constructing a torus Source Run 14
Transformation and Shared Branch Source Run 15
- Slides: 15