Graphics Transformations kucg korea ac kr Graphics Lab
Graphics Transformations 고려대학교 컴퓨터 그래픽스 연구실 kucg. korea. ac. kr Graphics Lab @ Korea University
Contents n KUCG Affine transformations n rotation, translation, and scaling Transformations in homogeneous coordinates n Concatenation of transformations n rotation about a fixed point n general rotation n instance transformation n rotation about an arbitrary axis n Open. GL transformation matrices n Smooth rotation with a virtual trackball n kucg. korea. ac. kr Graphics Lab @ Korea University
Transformations n KUCG Take a point (or vector) and map that point (or vector) into another point (or vector) u v 4 D column matrices R P homogeneous coordinate T Q transformation function kucg. korea. ac. kr Graphics Lab @ Korea University
Affine Transformations (1/2) n Linearity – linear function n Linear transformation n KUCG transform the representation of a point (or vector) into another representation of a point (or vector) 4 4 matrix kucg. korea. ac. kr vector point Graphics Lab @ Korea University
Affine Transformations (2/2) n KUCG Linear transformation (cont’) n preserve lines – transform a line into another line homogeneous coordinate affine transformation only transform the endpoints of a line segment n Most transformations in CG are affine n rotation, translation, scaling, and shear kucg. korea. ac. kr Graphics Lab @ Korea University
Translation n KUCG Operation that displace points by a fixed distance in a given direction n displacement vector d (a) object in original position kucg. korea. ac. kr (b) object translated Graphics Lab @ Korea University
Rotation (1/2) n KUCG Simple example of 2 D rotation kucg. korea. ac. kr Graphics Lab @ Korea University
Rotation (1/2) n KUCG Simple example of 2 D rotation kucg. korea. ac. kr Graphics Lab @ Korea University
Rotation (1/2) n KUCG Simple example of 2 D rotation kucg. korea. ac. kr Graphics Lab @ Korea University
Rotation (2/2) n KUCG Needs fixed point – a point is unchanged by the rotation n rotation angle – positive rotation (counterclockwise in right hand system) n rotation axis in 3 D – values on axis are unchanged by the rotation n (a) rotation about a fixed point kucg. korea. ac. kr (b) 3 D rotation Graphics Lab @ Korea University
Rigid-Body Transformations KUCG Rotation and translation n No combination of rotations and translations can alter the shape of object n alter only the object’s location and orientation affine transformations, but non-rigid body transformations kucg. korea. ac. kr Graphics Lab @ Korea University
Scaling (1/2) n KUCG Make an object bigger or smaller n uniform – scaling in all directions nonuniform n Affine non-rigid body transformation n affine transformation: translation, rotation, scaling, shear kucg. korea. ac. kr Graphics Lab @ Korea University
Scaling (2/2) n KUCG Needs fixed point n direction to scale n scale factor n o n longer (α>1) or smaller (0≤α<1) effect of scale factor Reflection – negative scale factor reflection kucg. korea. ac. kr Graphics Lab @ Korea University
Transformations in Homogeneous Coordinates KUCG n Representations in homogeneous coordinates n Affine transformation – 4 4 matrix kucg. korea. ac. kr Graphics Lab @ Korea University
Translation n KUCG Point p to p’ by displacing by a distance d ? translation matrix kucg. korea. ac. kr Graphics Lab @ Korea University
Translation n KUCG Point p to p’ by displacing by a distance d kucg. korea. ac. kr Graphics Lab @ Korea University
Translation KUCG n Point p to p’ by displacing by a distance d n Inverse of a translation matrix ? kucg. korea. ac. kr Graphics Lab @ Korea University
Translation KUCG n Point p to p’ by displacing by a distance d n Inverse of a translation matrix kucg. korea. ac. kr Graphics Lab @ Korea University
Scaling n KUCG Scaling matrix with a fixed point of the origin ? scaling matrix kucg. korea. ac. kr Graphics Lab @ Korea University
Scaling n KUCG Scaling matrix with a fixed point of the origin kucg. korea. ac. kr Graphics Lab @ Korea University
Scaling KUCG n Scaling matrix with a fixed point of the origin n Inverse of a scaling matrix ? kucg. korea. ac. kr Graphics Lab @ Korea University
Scaling KUCG n Scaling matrix with a fixed point of the origin n Inverse of a scaling matrix kucg. korea. ac. kr Graphics Lab @ Korea University
Rotation (1/2) n KUCG Rotation with a fixed point at the origin ? rotation matrix kucg. korea. ac. kr Graphics Lab @ Korea University
Rotation (1/2) n KUCG Rotation with a fixed point at the origin ? kucg. korea. ac. kr Graphics Lab @ Korea University
Rotation (1/2) n KUCG Rotation with a fixed point at the origin ? kucg. korea. ac. kr Graphics Lab @ Korea University
Rotation (1/2) n KUCG Rotation with a fixed point at the origin kucg. korea. ac. kr Graphics Lab @ Korea University
Rotation (2/2) n KUCG Inverse of a rotation matrix ? kucg. korea. ac. kr Graphics Lab @ Korea University
Rotation (2/2) n KUCG Inverse of a rotation matrix : orthogonal matrix kucg. korea. ac. kr Graphics Lab @ Korea University
Shear (1/2) n KUCG One more affine transformation shear the object in the x direction ? kucg. korea. ac. kr Graphics Lab @ Korea University
Shear (1/2) n KUCG One more affine transformation shear the object in the x direction kucg. korea. ac. kr Graphics Lab @ Korea University
Shear (2/2) n KUCG Shear in the x direction ? shearing matrix kucg. korea. ac. kr Graphics Lab @ Korea University
Shear (2/2) n KUCG Shear in the x direction kucg. korea. ac. kr Graphics Lab @ Korea University
Shear (2/2) KUCG n Shear in the x direction n Inverse of a shearing matrix ? kucg. korea. ac. kr Graphics Lab @ Korea University
Shear (2/2) n Shear in the x direction n Inverse of a shearing matrix kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
Concatenation of Transformations n KUCG Concatenating affine transformations by multiplying together n sequences of the basic transformations define an arbitrary transformation directly n ex) three successive transformations n p A B C q CBA p kucg. korea. ac. kr M q Graphics Lab @ Korea University
Rotation about a Fixed Point (1/3) n KUCG Fixed point: pf n apply Rz( ) to rotation about a fixed point rotation of a cube about its center kucg. korea. ac. kr Graphics Lab @ Korea University
Rotation about a Fixed Point (2/3) KUCG sequence of transformations kucg. korea. ac. kr Graphics Lab @ Korea University
Rotation about a Fixed Point (3/3) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
General Rotation (1/2) n KUCG Three successive rotations about the three axes rotation of a cube about the z axis rotation of a cube about the y axis ? rotation of a cube about the x axis kucg. korea. ac. kr Graphics Lab @ Korea University
General Rotation (2/2) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
Instance Transformation (1/2) n Instance of an object’s prototype n n KUCG occurrence of that object in the scene Instance transformation n applying an affine transformation to the prototype to obtain desired size, orientation, and location ? instance transformation kucg. korea. ac. kr Graphics Lab @ Korea University
Instance Transformation (2/2) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
Rotation about an Arbitrary Axis (1/6) n KUCG Needs fixed point: p 0 n rotation angle: θ n rotation axis: vector p 2 -p 1 n rotation of a cube about an arbitrary axis kucg. korea. ac. kr Graphics Lab @ Korea University
Rotation about an Arbitrary Axis (2/6) KUCG n First transformation is translation T(-p 0) and the final one is T(p 0) n Rotation problem!!! we can get an arbitrary rotation from three rotations about individual axes carry out two rotations to align the axis of rotation with the z axis rotate by θ about the z axis n kucg. korea. ac. kr movement of the fixed point to the origin Graphics Lab @ Korea University
Rotation about an Arbitrary Axis (3/6) KUCG sequence of rotations n Determine x and y n direction angles and cosines direction angles kucg. korea. ac. kr Graphics Lab @ Korea University
Rotation about an Arbitrary Axis (4/6) n KUCG Determine x and y (cont’) n projection line segment into plane y=0 o look at the projection of line segment (before rotation) on the plane x=0 computation of the x rotation kucg. korea. ac. kr Graphics Lab @ Korea University
Rotation about an Arbitrary Axis (5/6) n KUCG Determine x and y (cont’) n projection line segment into z axis rotation about y axis o caution!!! – clockwise angle o computation of the y rotation kucg. korea. ac. kr Graphics Lab @ Korea University
Rotation about an Arbitrary Axis (6/6) KUCG n Finally concatenate all the matrices n Ex) rotate an object by 45 degrees about the line passing through the origin and the point (1, 2, 3), fixed point is the origin n solution – textbook p. 195~196 kucg. korea. ac. kr Graphics Lab @ Korea University
Open. GL Transformation Matrices (1/2) n KUCG CTM (Current Transformation Matrix) matrix that is applied to any vertex n part of the pipeline n vertices CTM : replacement n : initialization operation: n : postmultiplication n kucg. korea. ac. kr Graphics Lab @ Korea University
Open. GL Transformation Matrices (2/2) n KUCG Matrix modes n model-view and projection matrices vertices model-view projection vertices CTM n Three functions: rotation, translation, scaling gl. Rotatef(angle, vx, vy, vz); gl. Translatef(dx, dy, dz); gl. Scalef(sx, sy, sz); kucg. korea. ac. kr Graphics Lab @ Korea University
Example: Rotation about a Fixed Point in Open. GL n KUCG Needs fixed point: (4, 5, 6) n rotation angle: 45 degrees n rotation axis: the line through the origin and the point (1, 2, 3) n kucg. korea. ac. kr Graphics Lab @ Korea University
Example: Rotation about a Fixed Point in Open. GL n KUCG Needs fixed point: (4, 5, 6) n rotation angle: 45 degrees n rotation axis: the line through the origin and the point (1, 2, 3) n gl. Matrix. Mode(GL_MODELVIWE); gl. Load. Identity( ); gl. Translatef(4. 0, 5. 0, 6. 0); gl. Rotatef(45. 0, 1. 0, 2. 0, 3. 0); gl. Translatef(-4. 0, -5. 0, -6. 0); kucg. korea. ac. kr Graphics Lab @ Korea University
Rotating a Cube (1/2) KUCG glut. Display. Func(display); glut. Idle. Func(spin. Cube); glut. Mouse. Func(mouse); void display(void) { gl. Clear(GL_COLOR_BUFFER_BIT | gl. Load. Identity(); gl. Rotatef(theta[0], 1. 0, 0. 0, gl. Rotatef(theta[1], 0. 0, 1. 0, gl. Rotatef(theta[2], 0. 0, colorcube(); glut. Swap. Buffers(); } GL_DEPTH_BUFFER_BIT); 0. 0); 1. 0); void mouse(int btn, int state, int x, int y) { if(btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN) axis=0; if(btn==GLUT_MIDDLE_BUTTON && state==GLUT_DOWN) axis=1; if(btn==GLUT_RIGHT_BUTTON && state==GLUT_DOWN) axis=2; } kucg. korea. ac. kr Graphics Lab @ Korea University
Rotating a Cube (2/2) KUCG void spin. Cube(void) { theta[axis] += 2. 0; if( theta[axis] > 360. 0 ) theta[axis] -= 360. 0; glut. Post. Redisplay(); } void mykey(char key, int mousex, int mousey) { if( key == ‘q’ || key == ‘Q’ ) exit(); } kucg. korea. ac. kr Graphics Lab @ Korea University
Rotating a Cube (2/2) KUCG void spin. Cube(void) { theta[axis] += 2. 0; if( theta[axis] > 360. 0 ) theta[axis] -= 360. 0; glut. Post. Redisplay(); } void mykey(char key, int mousex, int mousey) { if( key == ‘q’ || key == ‘Q’ ) exit(); } n gl. Push. Matrix( ), gl. Pop. Matrix( ) n perform a transformation and then return to the same gl. Push. Matrix(); state as before its execution o ex) instance transformation kucg. korea. ac. kr gl. Translatef(. . . ); gl. Rotatef(. . . ); gl. Scalef(. . . ); /* draw object here */ gl. Pop. Matrix(); Graphics Lab @ Korea University
Virtual Trackball (1/3) KUCG Use the mouse position to control rotation about two axes n Support continuous rotations of objects n trackball frame kucg. korea. ac. kr Graphics Lab @ Korea University
Virtual Trackball (2/3) n KUCG Rotation with a virtual trackball n projection of the trackball position to the plane kucg. korea. ac. kr Graphics Lab @ Korea University
Virtual Trackball (3/3) n KUCG Rotation with a virtual trackball (cont’) n determination of the orientation of a plane n rotation angle Quaternions kucg. korea. ac. kr Graphics Lab @ Korea University
Complex Numbers (1/3) n KUCG Real part + imaginary part: imaginary axis z y n Addition and subtraction n Scalar multiplication n Multiplication kucg. korea. ac. kr x real axis Graphics Lab @ Korea University
Complex Numbers (2/3) n Imaginary unit: n Complex conjugate n n KUCG modulus or absolute value Division kucg. korea. ac. kr Graphics Lab @ Korea University
Complex Numbers (3/3) KUCG n Representation with polar coordinates n Euler’s formula Imaginary axis n Complex multiplication and division n nth roots kucg. korea. ac. kr r z=(x, y) θ real axis Graphics Lab @ Korea University
Quaternions (1/2) n One real part + three imaginary part n Properties: n Addition and scalar multiplication kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
Quaternions (2/2) n KUCG Ordered-pair notation n scalar ‘s’ + vector “v = (a, b, c)” Addition: n Multiplication n n Magnitude n Inverse kucg. korea. ac. kr Graphics Lab @ Korea University
Quaternions and 3 D Rotation n For a 3 D point (α, β, γ) n a unit quaternion n KUCG its conjugate Rotating (α, β, γ) by angle 2θ about the axis parallel to (ux, uy, uz) For Rq is a 3 D rotation about (ux, uy, uz) by 2θ kucg. korea. ac. kr Graphics Lab @ Korea University
Rotations with Quaternions (1/2) n KUCG Rotation about any axis n set up a unit quaternion (u: unit vector) n represent any point position P in quaternion notation (p = (x, y, z)) n carry out with the quaternion operation (q-1=(s, –v)) n produce the new quaternion kucg. korea. ac. kr Graphics Lab @ Korea University
Rotations with Quaternions (2/2) n Obtain the rotation matrix by quaternion multiplication n Include the translations kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
Example n KUCG Rotation about z axis Set the unit quaternion: n Substitute a=b=0, c=sin(θ/2) into the matrix: n kucg. korea. ac. kr Graphics Lab @ Korea University
- Slides: 67