2010-1 학기 Chapter 5. Geometric Transformations 1.

Slides:



Advertisements
Similar presentations
3D Transformations Assist. Prof. Dr. Ahmet Sayar
Advertisements

Computer Graphics: 3D Transformations
Computer Graphics 2D & 3D Transformation.
COMPUTER GRAPHICS 2D TRANSFORMATIONS.
Gursharan Singh Tatla TRANSFORMATIONS Gursharan Singh Tatla Gursharan Singh Tatla.
OPENGL.
1 Computer Graphics Chapter 6 2D Transformations.
Chapter 5 Geometric Transformations
Two-Dimensional Geometric Transformations
CMPE 466 COMPUTER GRAPHICS
Math 1Hofstra University – CSC171A1 Modeling Objects by Polygonal Approximations Define volumetric objects in terms of surfaces patches that surround the.
Informationsteknologi Monday, November 12, 2007Computer Graphics - Class 71 Today’s class Viewing transformation Menus Mandelbrot set and pixel drawing.
CMPE 466 COMPUTER GRAPHICS
Elementary 3D Transformations - a "Graphics Engine" Transformation procedures Transformations of coordinate systems Translation Scaling Rotation.
Modeling Objects by Polygonal Approximations
Objectives Learn to build arbitrary transformation matrices from simple transformations Learn to build arbitrary transformation matrices from simple transformations.
Computer Graphics with OpenGL 3e
2IV60 Computer Graphics 2D transformations
2D Transformations x y x y x y. 2D Transformation Given a 2D object, transformation is to change the object’s Position (translation) Size (scaling) Orientation.
3D Transformation. In 3D, we have x, y, and z. We will continue use column vectors:. Homogenous systems:. 3D Transformation glVertex3f(x, y,z);
COS 397 Computer Graphics Svetla Boytcheva AUBG, Spring 2013.
5.2 Three-Dimensional Geometric and Modeling Transformations 2D3D Consideration for the z coordinate.
Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations.
Transformation of Graphics
TWO DIMENSIONAL GEOMETRIC TRANSFORMATIONS CA 302 Computer Graphics and Visual Programming Aydın Öztürk
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
Graphics Graphics Korea University kucg.korea.ac.kr Transformations 고려대학교 컴퓨터 그래픽스 연구실.
2D Transformation of Graphics
2D Transformations.
Geometric Transformations Jehee Lee Seoul National University.
Part7: Geometric Transformations
 2D Transformations 2D Transformations  Translation Translation  Rotation Rotation  Scaling Scaling.
3D Viewing.
Geometric Transformations
Computer Graphics 2D Transformations. 2 of 74 Contents In today’s lecture we’ll cover the following: –Why transformations –Transformations Translation.
Computer Graphics I, Fall 2010 OpenGL Transformations.
3D Transformations. Translation x’ = x + tx y’ = y + ty z’ = z + tz P = P’ = T = P’ = T. P tx ty tz xyz1xyz1 x’ y’ z’ 1 x y.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 OpenGL Transformations.
Two-Dimensional Geometric Transformations A two dimensional transformation is any operation on a point in space (x, y) that maps that point's coordinates.
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
Geometric Transformations
Transformations Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
2D Geometric Transformation Translation A translation is applied to an object by repositioning it along a straight-line path from one coordinate location.
Geometric Transformations Sang Il Park Sejong University Many slides come from Jehee Lee’s.
Geometric Transformations UBI 516 Advanced Computer Graphics Aydın Öztürk
January 19, y X Z Translations Objects are usually defined relative to their own coordinate system. We can translate points in space to new positions.
CS552: Computer Graphics Lecture 4: 2D Graphics. Recap 2D Graphics Coordinate systems 2D Transformations o Translation o Scaling o Rotation Combining.
Chap 3 Viewing and Transformation
CS552: Computer Graphics Lecture 6: Viewing in 2D.
Learning Objectives Affine transformations Affine transformations Translation Translation Rotation Rotation Scaling Scaling Reflection Reflection Shear.
Comp 175C - Computer Graphics Dan Hebert Computer Graphics Comp 175 Chapter 4 Instructor: Dan Hebert.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 73 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 73 Computer Graphics Three-Dimensional Graphics II.
1 OpenGL Transformations. 2 Objectives Learn how to carry out transformations in OpenGL ­Rotation ­Translation ­Scaling Introduce OpenGL matrix modes.
Homogeneous Coordinates and Matrix Representations Cartesian coordinate (x, y, z) Homogeneous coordinate (x h, y h, z h, h) Usually h = 1. But there are.
1 Geometric Transformations-II Modelling Transforms By Dr.Ureerat Suksawatchon.
Geometric Transformations. Transformations Linear transformations Rigid transformations Affine transformations Projective transformations T Global reference.
Jinxiang Chai CSCE441: Computer Graphics 3D Transformations 0.
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
2D Transformations What is transformations? The geometrical changes of an object from a current state to modified state. Why the transformations is needed?
CSCE 441 Computer Graphics: 2D Transformations
4. Geometric Objects and Transformations
Forward Projection Pipeline and Transformations CENG 477 Introduction to Computer Graphics.
Chapter 11 Three-Dimensional Geometric and Modeling Transformations
Geometric Transformations
2D Geometric Transformations
Line and Character Attributes 2-D Transformation
Unit-5 Geometric Objects and Transformations-II
Transformations 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
Geometric Objects and Transformations (II)
Lecture #6 2D Geometric Transformations
Presentation transcript:

학기 Chapter 5. Geometric Transformations 1

학기 Chapter 5. Geometric Transformations 2 Basic Transformations  Translation  물체의 위치를 straight line path 를 따라 한 좌표점에서 다른 좌표점으로 이동시 키는 것  (x, y) -> (x’, y’) 로 이동시킬 때  x’ = x + tx, y’ = y + ty  이때 (tx, ty) 를 translation vector 혹은 shift vector 라고 함  matrix 형태로 2 차원 평행이동식을 쓰면  P’ = P + T  P = x1P’ = x1’T = tx x2x2’ty

학기 Chapter 5. Geometric Transformations 3 Figure 5-1 Translating a point from position P to position P’ with translation vector T P P’ T

학기 Chapter 5. Geometric Transformations 4 Figure 5-2 Moving a polygon x y x y

학기 Chapter 5. Geometric Transformations 5  Rotation  xy plane 에서 물체를 circular path 를 따라 이동시키는 것으로 rotation angle 과 rotation point(pivot point) 가 필요  ( 그림 5-4) 에서  x’ = rcos (  +  ) = rcos  cos  - rsin  sin   y’ = rsin (  +  ) = rcos  sin  + rsin  cos  로 구해짐.  x = rcos , y = rsin  이므로  x’ = xcos  - ysin   y’ = xsin  + ycos   matrix 형태로 표시하면  P’ = R P  R = cos  -sin  sin  cos 

학기 Chapter 5. Geometric Transformations 6 Figure 5-3 Rotation of an object through angle about a pivot point (Xr, Yr)  P P’ Xr Yr

학기 Chapter 5. Geometric Transformations 7 Figure 5-4 Rotation of a point from position(x,y) to position (x’, y’) through an angle  (x, y) (x’, y’)  r r

학기 Chapter 5. Geometric Transformations 8  임의의 pivot position 을 중심으로 한 점을 회전시켰을 때 ( 그림 5-5)  x’ = xr + (x - xr) cos  - (y - yr) sin   y’ = yr + (x - xr) sin  + (y - yr) cos 

학기 Chapter 5. Geometric Transformations 9 Figure 5-5 Rotating a point from position (x, y) to position (x’, y’) through an angle about rotation point (xr, yr)  (x, y) (x’, y’)  r r (xr, yr)

학기 Chapter 5. Geometric Transformations 10  Scaling  물체의 크기 변환  각 vertex ( 정점 ) 의 좌표치에 scaling factors 인 sx, sy 를 곱해서 얻음  x’ = x ·sx, y’ = y · sy  matrix 형태로 표현하면 x’ = sx 0 x y’ 0 sy y Or P’ = S · P

학기 Chapter 5. Geometric Transformations 11 Matrix Representations and Homogeneous Coordinates  basic transformation 을 matrix 형태로 표현하면  P’ = M1 · P + M2  P and P’ -> column vectors  M1-> 2 by 2 array  M2 -> two-element column matrix  final coordinate positions 이 중간의 좌표점을 구하지않고 처음 좌표점에서 직접 구하 는 것이 효과적이다 이를 위해 M2 와 관련된 matrix addition 을 없애는 것이 필요  2 by 2 matrix representation 을 3 by 3 matrix representation 으로 바꾸어  모든 transformation equation 을 matrix multiplication 으로 나타낼 수 있도록 함

학기 Chapter 5. Geometric Transformations 12  two-dimensional transformation 을 a matrix multiplication 으로 표현하기 위해서  각 coordinate position (x, y) 를 homogeneous coordinate triple (xh, yh, h) 로 나타낸 다. ( 이때 x = xh / h, y = yh /h)  가장 간단한 형태로는 2 차원 점의 위치를 (x, y, 1) 로 표현하는 것

학기 Chapter 5. Geometric Transformations 13  Translation x’ 1 0 tx x y’ = 0 1 ty · y  Rotation x’ cos  -sin  0 x y’ = sin  cos  0 · y  Scaling x’ sx 0 0 x y’ = 0 sy 0 · y

학기 Chapter 5. Geometric Transformations 14 Figure 5-7 A line scaled using sx = sy = 0.5

학기 Chapter 5. Geometric Transformations 15 Figure 5-8 Scaling relative to a chosen fixed point (xf, yf) P1 P2 P3 (xf, yf)

학기 Chapter 5. Geometric Transformations 16 Composite Transformation  Translations  두 개 연속된 translation vectors (tx1, ty1), (tx2, ty2) 가 점 P 에 적용되면  P’ = T(tx2, ty2) · {T(tx1, ty1) · P}  = { T(tx2, ty2) · T(tx1, ty1)} · P 로 계산됨  여기에서 P 와 P’ 는 homogeneous-coordinate column vectors 로 나타냄  composite translation matrix 는 1 0 tx2 1 0 tx1 1 0 tx1+tx2 0 1 ty2 · 0 1 ty1 = 0 1 ty1+ty Or  T(x2, ty2) · T(x1, ty1) = T(x1+tx2, ty1+ty2)

학기 Chapter 5. Geometric Transformations 17  Rotations  Two successive rotations applied to point P: P’ = R(  2) · {R(  1) · P} = {R(  2) · R(  1)} · P = R(  1 +  2) · P  Scaling  Two successive scaling operations: sx2 0 0 sx1 0 0 sx1 ·sx sx2 0 · 0 sy1 0 = 0 sy1 · sy Or  S(sx2, sy2) · S(sx1, sy1) = S(sx1 · sx2, sy1 · sy2)

학기 Chapter 5. Geometric Transformations 18  General pivot point rotation ( 그림 5-9) 1) 회전의 중심점을 원점으로 이동시킨다 2) 원점을 중심으로 물체를 회전시킨다 3) 중심점을 원래의 점으로 이동시킨다  composite transformation matrix:  회전의 중심점 (pivot point) 가 (xr, yr) 일때 1 0 xr cos  -sin  xr 0 1 yr · sin  cos  0 · 0 1 -yr

학기 Chapter 5. Geometric Transformations 19 Figure 5-9 A transformation sequence for rotating an object about a specified pivot point (xr, yr)

학기 Chapter 5. Geometric Transformations 20 cos  -sin  xr(1-cos  )+yr sin  = sin  cos  yr(1-cos  )-xr sin  0 0 1

학기 Chapter 5. Geometric Transformations 21 General Fixed-Point Scaling ( 그림 5-10)  계산순서  고정점이 원점에 위치하도록 이동한다  원점에 대해 물체의 크기 변환 계산을 한다  물체를 원래의 고정점으로 이동한다. 1 0 xf sx xf sx 0 xf(1-sx) 0 1 yf · 0 sy 0 · 0 1 -yf = 0 sy yf(1-sy)

학기 Chapter 5. Geometric Transformations 22 Figure 5-10 A transformation sequence for scaling an object about a specified fixed point (xr, yr)

학기 Chapter 5. Geometric Transformations 23 General Scaling Direction ( 그림 5-11)  x, y direction 이 아닌 임의의 방향으로 물체의 크기를 조정하기 위해선 원하는 방향 축을 원점으로 회전시킨후에 scaling transformation 을 적용한다. R -1 (  ) · S(s1, s2) · R(  ) s1cos 2  +s2sin 2  (s2-s1)cos  sin  0 = (s2-s1)cos  sin  s1sin 2  +s2cos 2 

학기 Chapter 5. Geometric Transformations 24 Figure 5-11 Scaling parameters s1 and s2 are to be applied in orthogonal directions defined by the angular displacement  x y s1 s2 

학기 Chapter 5. Geometric Transformations 25  rigid-body transformation matrix: translation 과 rotation 만 포함하는 경우 rxx rxy trx ryx ryy try  윗 부분의 2 by 2 submatrix 는 orthogonal matrix 이다  두 벡터 (rxx, rxy), (ryx, ryy) 가 서로 수직인 단위벡터를 형성 : 1) 각 벡터는 단위 길이를 가지며 r xx 2 + r xy 2 = r yx 2 + r yy 2 = 1 2) 두 벡터는 서로 수직이다 (dot product 가 0) r xx r yx + r xy r yy = 0

학기 Chapter 5. Geometric Transformations 26 Other Transformations  Reflection ( 그림 5-16)( 그림 5-17)  물체의 miror image 를 계산  반사축을 중심으로 180 도 회전하여 구함  x-axis (y = 0) 을 중심으로 한 reflection 을 위한 transformation matrix  reflection about y axis

학기 Chapter 5. Geometric Transformations 27 Figure 5-16 Reflection of an object about the x-axis Original Position Reflected Position

학기 Chapter 5. Geometric Transformations 28 Figure 5-17 Reflection of an object about y-axix Original Position Reflected Position

학기 Chapter 5. Geometric Transformations 29  reflection relative to origin  reflection about y=x ( 그림 5-21) 1) 시계방향으로 45 도 회전하여 y=x 선을 x 축에 일치시킨다. 2) x 축을 중심으로한 반사를 구함 3) y=x 선을 반시계방향으로 45 도 회전

학기 Chapter 5. Geometric Transformations 30 Figure 5-21 Sequence of transformations to produce reflection about the line y = x y = x  y = x 

학기 Chapter 5. Geometric Transformations 31  Shear ( 그림 5-23)( 그림 5-25)  물체의 내부가 미끄러진 형태로 모양을 변형시키는 것  x-direction shear relative to x-axis 1 shx  x ‘ = x + shx * y  y’ = y  x-diretcion shear relative to the line y = yref 1 shx -shx*yref

학기 Chapter 5. Geometric Transformations 32  y-direction shear relative to the line x = xref shy 1 -shy*xref 0 0 1

학기 Chapter 5. Geometric Transformations 33 Figure 5-23 x-direction shear

학기 Chapter 5. Geometric Transformations 34 Figure 5-24 y-direction shear

학기 Chapter 5. Geometric Transformations 35 Raster Methods for Geometric Transformations  사각형의 pixel array 를 다루는 raster functions 을 raster ops 라고 한다.  block transfer: 픽셀 블럭을 한 위치에서 다른 위치로 이동시키는 것  bilevel system 에서는 bitBlt (bit-block transfer) 라고 부름  그래픽스 패키지에서 제공하는 raster functions  copy: 한 픽셀 블럭을 한 위치에서 다른 위치로 이동시킴  read: 픽셀 블럭을 지정된 배열에 저장함  write: 픽셀 배열을 프레임버퍼내 한 위치로 보냄  pixel value 를 결합시키는 처리로 :  replace: pixel values 가 목적지에 이동됨  Boolean operations: and, or, exclusive-or  Rotations  raster scaling of a block of pixels

학기 Chapter 5. Geometric Transformations 36 OpenGL Raster Transformations  glCopyPixels (xmin, ymin, width, height, GL_COLOR);  glReadPixels (xmin, ymin, width, height, GL_RGB, GL_UNSIGNED_BYTE, colorArray); // or GL_COLOR_INDEX  glDrawPixels (width, height, GL_RGB, GL_UNSIGNED_BYTE, colorArray); // current raster position  glPixelZoom (sx, sy);

학기 Chapter 5. Geometric Transformations 37 Figure 5-26 Translating an object from screen position to the destination postion P min P max P0P0

학기 Chapter 5. Geometric Transformations 38 Figure 5-27 Rotating an array of pixel values ° counterclockwise rotation 180° counterclockwise rotation

학기 Chapter 5. Geometric Transformations 39 Transformations between two-dimensional coordinate systems  xy coordinates 에서 x’y’ coordinates 로 바뀌기 위해선 x’y’ 축을 xy 축에 겹쳐놓는 작 업이 필요하다  x’y’ system 의 원점을 xy sytem 의 원점으로 이동시킨다 ( 그림 5-31)  x’ 축을 x 축까지 회전시킨다.  transformation matrix :  M xy,x’y’ = R(-  ) · T(-x0, -y0)

학기 Chapter 5. Geometric Transformations 40 Figure 5-30 Cartesian x’y’ system x0 y0  x’ axis y’ axis

학기 Chapter 5. Geometric Transformations 41 Figure 5-31 Position of the reference frames after translating the origin x0 y0  x’ axis y’ axis

학기 Chapter 5. Geometric Transformations 42  또 다른 방법으로, positive y’ 방향을 나타내는 벡터 V 를 지정한다 ( 그림 5- 32)  y’ 방향의 단위벡터는 v = V = (vx, vy) |V|  x’ 축의 단위벡터 u 는 v 를 90 도 회전하여 구해짐 u = (vy, -vx) = (ux, uy)  rotation matrix 는 orthogonal unit vectors 로 나타낼 수 있으므로 x’y’ system 을 xy system 으로 회전하는데 필요한 matrix 는 ux uy 0 R = vx vy 가 된다.

학기 Chapter 5. Geometric Transformations 43 Figure 5-32 Cartesian system x’y’ with origin at P0 = (x0, y0) x0 y0 x’ axis y’ axis P0 V

학기 Chapter 5. Geometric Transformations 44  응용에 따라 벡터 V 를 다음과 같이 정의하여 사용 ( 그림 5-33) v = P1 - P0 |P1 - P0|

학기 Chapter 5. Geometric Transformations 45 Figure 5-33 A Cartesian x’y’ system defined with two coordinate positions, p0 and p1 x0 y0 x’ axis y’ axis P0 V = P1 – P0 P1

학기 Chapter 5. Geometric Transformations 46 Three-Dimensional Translation  position P = (x, y, z) 에서 P’ = (x’, y’, z’) 로 이동시키는 matrix operation 은 x’ tx x y’ = ty · y z’ tz z  혹은  P’ = T · P 로 나타냄

학기 Chapter 5. Geometric Transformations 47 Figure 5-34 Moving a coordinate position (x, y, z) (x’, y’, z’) T = (tx, ty, tz) x-axis y-axis z-axis

학기 Chapter 5. Geometric Transformations 48 Figure 5-35 Shifting the position of a three-dimensional object (x, y, z) (x’, y’, z’) T = (tx, ty, tz) x-axis y-axis z-axis

학기 Chapter 5. Geometric Transformations 49 Three-Dimensional Rotation  positive rotations angles: coordinate axis 를 중심으로 counterclockwise rotations 의 각 도 의미  coordinate axis rotations  z-axis rotation  x’ = xcos  - ysin   y’ = xsin  + ycos   z’ = z  homogeneous form 으로 나타내면 x’ cos  -sin  0 0 x y’ = sin  cos  0 1 · y z’ z

학기 Chapter 5. Geometric Transformations 50 Figure 5-36 Positive rotations about a coordinate axis x-axis y-axis z-axis x-axis y-axis z-axis x-axis y-axis z-axis

학기 Chapter 5. Geometric Transformations 51 Figure 5-37 Rotation of an object about the z axis x z y

학기 Chapter 5. Geometric Transformations 52  or P’ = Rz(  ) · P  x-axis rotation  y’ = ycos  - zsin   z’ = ysin  + zcos   x’ = x  homogeneous form 으로 나타내면 x’ x y’ = 0 cos  -sin  1 · y z’ 0 sin  cos  0 z or  P’ = Rx(  ) · P

학기 Chapter 5. Geometric Transformations 53  y-axis rotation  z’ = zcos  - xsin   x’ = zsin  + xcos   y’ = y  homogeneous matrix form 으로 나타내면 x’ cos  0 sin  0 x y’ = · y z’ -sin  0 cos  0 z or P’ = Ry(  ) · P

학기 Chapter 5. Geometric Transformations 54 General Three-Dimensional Rotations  one of coordinate axes 와 평행한 축을 중심으로 회전한 경우 1) rotation axis 가 parallel coordinate axis 에 일치하도록 object 를 이동시킨다 2) rotation axis 를 중심으로 회전 3) rotation axis 를 원래 위치로 이동  P’ = T -1 Rx(  ) T P

학기 Chapter 5. Geometric Transformations 55 Figure 5-41 Sequence of transformations for rotating an object about an axis that is parallel to the axis x y z Rotation axis x y z x y z x y z (a) original position of object (b) rotate object through angle  (c) translate rotation axis onto x axis (d) translate rotaion axis to original position

학기 Chapter 5. Geometric Transformations 56  one of coordinate axes 에 평행하지 않은 일반 축을 중심으로 회전한 경우 1) rotation axis 가 coordinate origin 을 통과하도록 object 를 이동 2) rotation axis 가 one of coordinate axes 와 일치하도록 object 를 회전 3) coordinate axis 를 중심으로 회전 4) rotation axis 가 원래의 방향으로 돌아오도록 inverse rotations 수행 5) rotation axis 가 원래의 위치로 돌아오도록 inverse translation 수행

학기 Chapter 5. Geometric Transformations 57 Figure 5-42 Five transformation steps for obtaining a composite matrix p1 p2 x y z Initial position p1’ p2 x y z Step1 translate p1 to the origin p1 p2” x y z Step2 rotate p2’ onto the z axis p1 p2” x y z Step3 rotate the object around the z axis p1’ p2 x y z Step4 rotate the axis to the original orientation p1 p2 x y z Step5 translate the rotation axis to the original position

학기 Chapter 5. Geometric Transformations 58  rotation axis 정의 ( 그림 5-43)  two coordinate positions 으로 정의 V = P 2 - P 1 = (x2- x1, y2- y1, z2 - z1)  rotation axis 의 unit vector u V U = = (a, b, c) |V| where a, b, c 는 rotation axis 의 direction cosines 로 다음과 같이 정의됨 x2 - x1 y2 - y1 z2 - z1 a = b = c = |V| |V| |V|

학기 Chapter 5. Geometric Transformations 59 Figure 5-43 An axis of rotation defined with points P1 and P2 p1 p2 u x y z

학기 Chapter 5. Geometric Transformations 60 Figure 5-44 Translation of the rotation axis to the coordinate origin x y z u

학기 Chapter 5. Geometric Transformations 61 Figure 5-45 Unit vector u is rotated about the x axis bring it into the xz plane (a), then it is rotated around the y axis to align it with z axis (b) x y z u  x y z  u (a)(b)

학기 Chapter 5. Geometric Transformations 62 Figure 5-46 Rotation of u around the x axis into the xz plane is accomplished by rotating u’ (the projection of u in the yz plane) through angle  onto the z axis x y z u u’  u z = (0, 0, 1)

학기 Chapter 5. Geometric Transformations 63 Scalar product of two vectors: V1 V2 = |V1| |V2| cos  Vector product of two vectors: V1 X V2 = u |V1| |V2| sin  ux uy uz V1 X V2 = V 1x V 1y V 1z V 2x V 2y V 2z u’ = (0, b, c) Cos  = = u’ uz | u’| |uz| d c d = b 2 + c 2 uz = (0, 0, 1) u’ X uz = ux |u’| |uz| sin  u’ X uz = ux b x y z u u’  u z = (0, 0, 1)

학기 Chapter 5. Geometric Transformations 64 d sin  = b sin  = d b Rx(  ) = c/d -b/d 0 0 b/d c/d u’ X uz = ux |u’| |uz| sin  u’ X uz = ux b Scalar product of two vectors: V1 V2 = |V1| |V2| cos  Vector product of two vectors: V1 X V2 = u |V1| |V2| sin  ux uy uz V1 X V2 = V 1x V 1y V 1z V 2x V 2y V 2z x y z u u’  u z = (0, 0, 1)

학기 Chapter 5. Geometric Transformations 65 x  u” = (a, 0, d) uz = (0, 0, 1) Cos  = = d u” uz |u”| |uz| |uz| = |u”| = 1 u” X uz = uy |u”| |uz| sin  u” X uz = uy · (-a) sin  = -a Scalar product of two vectors: V1 V2 = |V1| |V2| cos  Vector product of two vectors: V1 X V2 = u |V1| |V2| sin  ux uy uz V1 X V2 = V 1x V 1y V 1z V 2x V 2y V 2z y

학기 Chapter 5. Geometric Transformations 66  전 과정에 필요한 matrix 표현 : 책 반드시 참고  R(  ) = T -1 Rx -1 (  ) Ry -1 (  ) Rz(  ) Ry(  ) Rx(  ) T Ry(  ) = d 0 -a a 0 d

학기 Chapter 5. Geometric Transformations Three-Dimensional Scaling  Scaling transformation matrix x’ Sx x y’ = 0 Sy 0 0 y z’ 0 0 Sz 1 z

학기 Chapter 5. Geometric Transformations 68 Figure 5-50 Doubling the size of an object x y z

학기 Chapter 5. Geometric Transformations 69  fixed position (xf, yf, zf) 에서의 scaling 1) fixed position 을 원점으로 이동 2) 원점에 대해 scaling 3) fixed position 을 원래의 위치로 이동 sx 0 0 (1-sx)xf T(xf, yf, zf) S(sx, sy, sz) T(-xf, -yf, -zf) = 0 sy 0 (1-sy) yf 0 0 sz (1-sz)zf

학기 Chapter 5. Geometric Transformations 70 Figure 5-51 A sequence of transformations for scaling an object relative to a selected fixed point (xf, yf, zf) (a) (xf, yf, zf) (b) (xf, yf, zf) (c) (xf, yf, zf) (d)

학기 Chapter 5. Geometric Transformations 71 Other Three-Dimensional Transformations  Reflections  3D reflection 은 reflection axis 혹은 reflection plane 에 대해 처리됨  reflection axis 의 경우엔 180 도 회전과 같고 reflection plane 의 경우엔 4 차원 공간 에서 180 도 회전과 같다. Reflection plane 이 xy, xz, yz 등 coordinate axis 의 경우엔 left-handed and right handed coordinate system 간의 변환과 같다.  Right-handed system 에서 left-handed system 으로 변환하는 reflection 은 x, y coordinates 는 변화가 없고 z coordinates 의 부호만 바뀌는 결과를 가져옴 RFz =  xy plane 에 대한 reflection 을 위한 매트릭스

학기 Chapter 5. Geometric Transformations 72 Figure 5-52 Conversion of coordinate specifications from a right-handed to a left-handed system x y z x y z Reflection relative to the xy plane

학기 Chapter 5. Geometric Transformations 73  Shears  z-axis shear 1 0 a b 0 SHz =  => z value 에 비례하여 x, y coordinate values 를 변화시킴 => z 값은 그대로 유지하고 x, y 값만 바뀜

학기 Chapter 5. Geometric Transformations 74 Affine Transformation  x’ = a xx x + a xy y + b x  y’ = a yx x + a yy y + b y  의 형태로 변환되는 것을 2 차원 affine transformation 이라고 함  affine transformation 의 성질  parallel lines 은 parallel lines 로 변화되고  finite points 는 finite points 로 매핑됨  translation, rotation, scaling, reflection, shear: two-dimensional affine transformation 의 대표적인 예  또 다른 예로 두 좌표계의 변환 등이 포함됨

학기 Chapter 5. Geometric Transformations 75 OpenGL Geometric-Transformation Functions  Basic OpenGL Geometric Transformations  glTranslate* (tx, ty, tz); // *: d or f (double or float)  glTranslatef (25.0, -10.0, 0.0);  glRotate* (theta, vx, vy, vz); // vx, vy, vz: 원점을 통과하는 회전축 방향 지정 // *: d or f (double or float), rotation angle in degrees  glRotatef (90.0, 0.0, 0.0, 1.0);  glScale* (sx, sy, sz); 

학기 Chapter 5. Geometric Transformations 76  OpenGL Matrix Operations  set up a matrix for the geometric Transformation  modelview matrix 사용  glMatrixMode (GL_MODELVIEW); // 4 by 4 modelview matrix 를 current matrix 로 // other modes: projection mode, texture mode, color mode  glLoadIdentity ( ); // identity matrix 를 current matrix 로  glLoadMatrix* (elements16); // current matrix 의 elements 를 다른 값으로 지정 // single-subscripted, 16-element array(floating-point values) 를 //elements16 으로 지정 glMatrixMode (GL_MODELVIEW); GLFloat elems [16]; GLint k;

학기 Chapter 5. Geometric Transformations 77 For (k = 0; k < 16; k++) elems [k] = float (k); GlLoadMatrixf (elems); => 결과 matrix: M =

학기 Chapter 5. Geometric Transformations 78 glMultMatrix* (otherelements16); // current matrix 가 otherelements16 으로 // 만들어진 matrix 와 곱해짐 // M = M  M’ glMatrixMode (GL_MODELVIEW); glLoadIdentity ( ); glMultMatrixf (elemsM2); glMultMatrixf (elemsM1); => M = M 2  M 1

학기 Chapter 5. Geometric Transformations 79  주의점 : OpenGL 은 column-major 로 matrix element 를 저장  즉, OpenGL 에서 m jk 는 column j 중 row k 라는 점  일반 matrix 와는 반대  16-elements single-subscripted array 로 matrix 를 지정하므로써 혼란을 피함  OpenGL Matrix Stacks  multiple views and transformation sequences 의 경우 각각에 대해 composite matrix 를 스택에 저장, 32 개 스택까지 가능  modelview 스택의 수를 정할 수 있음  glGetIntegerv (GL_MAX_MODELVIEW_STACK_DEPTH, stackSize);  glPushMatrix ( ); // current matrix 를 스택의 top 에 둠  glPopMatrix ( ); // 스택의 top 에 있는 matrix 를 없앰

학기 Chapter 5. Geometric Transformations 80 OpenGL Geometric Transformation Example # include void init (void) { glClearColor (1.0, 1.0, 1.0, 0.0); glMatrixMode (GL_PROJECTION); gluOrtho2D (-200.0, 200.0, , 200.0); //glMatrixMode (GL_MODELVIEW); } void displayFcn (void) {

학기 Chapter 5. Geometric Transformations 81 glClear(GL_COLOR_BUFFER_BIT); glMatrixMode (GL_MODELVIEW); glColor3f(0.0, 0.0, 1.0); glRecti(50, 100, 200, 150); glColor3f(1.0, 0.0, 0.0); glTranslatef(-100.0, , 0.0); glRecti(50, 100, 200, 150);

학기 Chapter 5. Geometric Transformations 82 glLoadIdentity(); glRotatef(90.0, 0.0, 0.0, 1.0); glRecti(50, 100, 200, 150); glLoadIdentity(); glScalef(-0.5, 1.0, 1.0); glRecti(50, 100, 200, 200); glFlush(); }

학기 Chapter 5. Geometric Transformations 83 void main(int argc, char **argv) { glutInit (&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowPosition(50, 50); glutInitWindowSize(600, 300); glutCreateWindow("GL_MODELVIEW Example"); init(); glutDisplayFunc(displayFcn); glutMainLoop(); }

학기 Chapter 5. Geometric Transformations 84

학기 Chapter 5. Geometric Transformations 85 Composite-transformation Example # include class wcPt2D { public: GLfloat x, y; }; class wcPt3D { public: GLfloat x, y, z; }; void init (void) {

학기 Chapter 5. Geometric Transformations 86 glClearColor (1.0, 1.0, 1.0, 0.0); glMatrixMode (GL_PROJECTION); gluOrtho2D (-100.0, 100.0, , 100.0); glMatrixMode (GL_MODELVIEW); } void triangle (wcPt2D *verts) { GLint k; glBegin (GL_TRIANGLES); for (k = 0; k < 3; k++) glVertex2f (verts[k].x, verts[k].y); glEnd (); }

학기 Chapter 5. Geometric Transformations 87 /* Procedure for generating a matrix for rotation about an axis defined with points p1 and p2 */ void rotate3D (wcPt3D p1, wcPt3D p2, GLfloat thetaDegrees) { float vx = (p2.x - p1.x); float vy = (p2.y - p1.y); float vz = (p2.z - p1.z); glTranslatef(p1.x, p1.y, p1.z); glRotatef(thetaDegrees, vx, vy, vz); glTranslatef(-p1.x, -p1.y, -p1.z); }

학기 Chapter 5. Geometric Transformations 88 /* Procedure for generating a matrix for a scaling transformation with respect to an arbitrary fixed point */ void scale3D (GLfloat sx, GLfloat sy, GLfloat sz, wcPt3D fixedPt) { glTranslatef(fixedPt.x, fixedPt.y, fixedPt.z); glScalef(sx, sy, sz); glTranslatef(-fixedPt.x, -fixedPt.y, -fixedPt.z); } void displayFcn (void) { wcPt2D verts [3] = {{-50.0, -25.0}, {50.0, -25.0}, {0.0, 50.0}}; wcPt3D fixedPt = {1.0, 1.0, 0.0}; wcPt3D p1 = {0.0, 0.0, 0.0}, p2 = {1.0, 0.0, 0.0}; GLfloat thetaDegrees = 10.0;

학기 Chapter 5. Geometric Transformations 89 glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.0, 0.0, 1.0); glViewport(0, 0, 500, 400); triangle(verts); glColor3f(1.0, 0.0, 0.0); scale3D(0.5, 0.5, 0.5, fixedPt); rotate3D(p1, p2, thetaDegrees); triangle(verts); glFlush(); }

학기 Chapter 5. Geometric Transformations 90 void main(int argc, char **argv) { glutInit (&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowPosition(50, 50); glutInitWindowSize(600, 500); glutCreateWindow("Geo-Trans Example"); init(); glutDisplayFunc(displayFcn); glutMainLoop(); }

학기 Chapter 5. Geometric Transformations 91