Overview Affine Transformations (2D and 3D) Coordinate System Transformations Vectors Rays and Intersections ITCS 4120/5120 1 Mathematical Fundamentals
Geometric Transformations A set of tools that aid in manipulating graphical objects and their coordinate systems Y Y D C M D B C A B X A X ITCS 4120/5120 2 Mathematical Fundamentals
Affine Transformations most common in computer graphics permits a simple matrix representation can be composed Definition P (P x, P y ) is transformed into Q(Q x, Q y ) as follows: Q x = ap x + cp y + T x Q y [ ] Qx Q y = bp x + dp y + T y = Q = [ ] [ ] a c Px + b d P y M P + T [ ] Tx T y ITCS 4120/5120 3 Mathematical Fundamentals
2D Primitive Affine Transformations Q = M P + T Translation [ ] Qx Q y M = T = = [ ] 1 0 = I (Identity) 0 1 [ ] Tx T y [ ] Px + T x P y + T y ITCS 4120/5120 4 Mathematical Fundamentals
Scale [ ] Qx Q y M = = [ ] Sx 0, T = [ 0 0 ] 0 S y [ ] Px S x P y S y S x = S y (Uniform Scaling) S x S y (Differential Scaling) ITCS 4120/5120 5 Mathematical Fundamentals
Rotation [ ] Cosθ Sinθ M = Sinθ Cosθ T = [ 0 0 ] Q = MP + T = P x Cosθ P y Sinθ = P x Sinθ + P y Cosθ Q x Q y Y Q y Q P y O θ R φ Exercise: Derive the above rotation matrix. ITCS 4120/5120 6 Mathematical Fundamentals R Q x P x P X
An Application of Affine Transforms (wx_max, wy_max) (vx_max, vy_max) (xw,yw) (wx_min, wy_min) (xv,yv) (vx_min, vy_min) Window to Viewport Transform Break M wv into a series of primitive transformations. 1. Translate a corner of window to the origin. 2. Scale window to unit size. 3. Scale window to viewport size. 4. Translate to viewport origin. ITCS 4120/5120 7 Mathematical Fundamentals
An Application of Affine Transforms (wx_max, wy_max) (vx_max, vy_max) (xw,yw) (wx_min, wy_min) (xv,yv) (vx_min, vy_min) 1. Translate window to the origin: T ( w xmin, w ymin ) 2. Scale window to unit size: S(S wx, S wy ) 3. Scale to viewport size: S(S vx, S vy ) 4. Translate to viewport origin: T (v xmin, v ymin ) M wv = T (v xmin, v ymin )S(S vx, S vy )S(S wx, S wy )T ( w xmin, w ymin ) ITCS 4120/5120 8 Mathematical Fundamentals
Homogeneous Coordinate Representation Motivation Translation: Q = P + T (Tx, T y ) Rotation: Scale: Q = R(θ) P Q = S(Sx, S y ) P Translation involves a vector addition instead of a vector-matrix multiplication. Better if all transforms are accomplished using a vector-matrix multiply. ITCS 4120/5120 9 Mathematical Fundamentals
Homogeneous Coordinates: Representing Points P 2d = (x, y), P H = (x, y, w) W P (x, y, w) W = 1 Plane X Y Points in 2D are the projection of points in homogeneous space onto the w = 1 plane. To convert from P H to P 2D, divide each coordinate by the w coordinate and discard the 3rd coordinate. w = 0 represents points at infinity. ITCS 4120/5120 10 Mathematical Fundamentals
Homogeneous Matrices Additional row and column T H (T x, T y ) = S H (S x, S y ) = R H (θ) = 1 0 T x 0 1 T y 0 0 1 S x 0 0 0 S y 0 0 0 1 Cosθ Sinθ 0 Sinθ Cosθ 0 0 0 1 ITCS 4120/5120 11 Mathematical Fundamentals
Homogeneous Matrices(contd) Hence Q = T H (T x, T y ) P Q = S H (S x, S y ) P Q = R H (θ) P In particular, 1 0 T x 0 1 T y P x P y = [ ] P x + T x, P y + T y 0 0 1 1 ITCS 4120/5120 12 Mathematical Fundamentals
Affine Transforms (contd.) Shear Transform: Q x = P x + hp y, Q y = gp x + P [ ] y 1 h M sh = g 1 g = 0 (X axis shear), h = 0 (Y axis shear) Y X Application X Shear (h > 0) 3D Viewing Pipeline ITCS 4120/5120 13 Mathematical Fundamentals
Reflection Transform Produces a mirror image about an axis of reflection. Y B B A A M y refl = M x refl = M = C C [ ] 1 0 Y axis reflection 0 1 [ ] 1 0 X axis reflection 0 1 [ ] 1 0 =?? 0 1 ITCS 4120/5120 14 Mathematical Fundamentals X
Affine Transform Inverses T 1 (T x, T y ) = T ( T x, T y ) S 1 (S x, S y ) = S(1/S x, 1/S y ) R 1 (θ) = [ ] Cosθ Sinθ Sinθ Cosθ = R T In general, MM 1 = M 1 M = I Exercise: Determine the inverse of M sh = [ ] 1 h. g 1 ITCS 4120/5120 15 Mathematical Fundamentals
Transformation About a Reference Point x r, yr Y Y M X X Strategy x, y r r = Reference point Translation of (x r, y r ) to the origin. Transform. Translate back by same amount. M = T (x r, y r ).S(S x, S y ).T ( x r, y r ) For rotation about a point, replace scale by a rotation transform. ITCS 4120/5120 16 Mathematical Fundamentals
Parametric Representations x(t) = x 0 + t(x 1 x 0 ) y(t) = y 0 + t(y 1 y 0 ) t (0.0, 1.0) corresponds to the segment from (x 0, y 0 ) to (x 1, y 1 ) In general, x(0) = x 0, x(1) = x 1 y(0) = y 0, y(1) = y 1 r(t) = p(t) + t d(t) where p(t) = origin, d(t) = direction vector. Application: Parametric Curves,Surfaces, Ray Tracing, Clipping ITCS 4120/5120 17 Mathematical Fundamentals
Properties of Affine Transforms Lines Remain Lines A t B P (t) = A + t( B A) Q(t) = M P (t) + T = M( A + t( B A)) + T = ( M A + T ) + tm( B A) which is also a line with origin ( A M + T ) and direction ( B A) M. ITCS 4120/5120 18 Mathematical Fundamentals
Parallel Lines Remain Parallel R 1 (t) = A 1 + βt R 2 (t) = A 2 + βt After Transformation, New Origins: A1 M + T, A2 M + T New Direction: βm ITCS 4120/5120 19 Mathematical Fundamentals
Transformation of Coordinate Systems j O P i M O v u Q To determine Q, in terms of P. u = v = M i = left column of M M j = right column of M How? [ ] [ ] u = M m00 m i = 01 1 = m 10 m 11 0 [ ] [ ] v = M m00 m j = 01 0 = m 10 m 11 1 [ m00 ] m 10 [ ] m01 m 11 ITCS 4120/5120 20 Mathematical Fundamentals
Transformation of Coordinate Systems(contd) M = [ u v ] j Tj b v a u P T (0, 0) Ti i P = a u + b v + T = [ u v ] [ ] a + T b [ a Q = = b] [ u v ] 1 [ ] P T = M [ ] 1 P T ITCS 4120/5120 21 Mathematical Fundamentals
3-D Affine Transformations Translation M t = 1 0 0 T x 0 1 0 T y 0 0 1 T z 0 0 0 1 ITCS 4120/5120 22 Mathematical Fundamentals
3-D Affine Transformations Rotation R z (θ) = R x (θ) = R y (θ) = Cosθ Sinθ 0 0 Sinθ Cosθ 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 Cosθ Sinθ 0 0 Sinθ Cosθ 0 0 0 0 1 Cosθ 0 Sinθ 0 0 1 0 0 Sinθ 0 Cosθ 0 0 0 0 1 ITCS 4120/5120 23 Mathematical Fundamentals
3-D Affine Transformations Scaling S x 0 0 0 0 S S(S x, S y, S z ) = y 0 0 0 0 S z 0 0 0 0 1 ITCS 4120/5120 24 Mathematical Fundamentals
Composing Affine Transforms If M 1, M 2,..., M n are affine transforms to be applied in succession to a point P. Q = (M n.(m n 1...(M 2.(M 1.P )...) = (M n.m n 1...M 3.M 2.M 1 )P For transforming large numbers of points, the matrix product (M 1.M 2.M 3...M n 1.M n ) needs to be performed only once. Example Y Y M comp X X M comp = T (T x, T y ).S(S x, S y ).R(θ).T ( T x, T y ) ITCS 4120/5120 25 Mathematical Fundamentals
3D Affine Transforms about pivot point Scaling Translate pivot point to origin. Scale by (S x, S y, S z ). Translate pivot point back. M = T (T x, T y, T z ).S(S x, S y, S z ).T ( T x, T y, T z ) ITCS 4120/5120 26 Mathematical Fundamentals
Rotation about Arbitrary Axis Y d P X Z Given P, point on axis and axis direction vector d ITCS 4120/5120 27 Mathematical Fundamentals
Rotation about Arbitrary Axis Y d P X Strategy Translate rotation axis to pass through origin. Align rotation axis with a coordinate axis. Rotate by given angle A Inverse Rotations. Inverse translations. Z M = T (T x, T y, T z )R y (θ)r x (φ)r y (A)R x ( φ)r y ( θ).t ( T x, T y, T z ) ITCS 4120/5120 28 Mathematical Fundamentals
Reflection (3D) M rl z = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 Similarly, M rl x and M rl y can be defined. Reflection about an arbitrarily oriented plane? ITCS 4120/5120 29 Mathematical Fundamentals
Properties of 3D Affine Transforms Lines are preserved. Parallel lines remain parallel after transformation. Proportional distances are preserved. Transformation of coordinate systems used in hierarchical modeling, 3D Viewing. ITCS 4120/5120 30 Mathematical Fundamentals
Vectors An entity that possesses both magnitude and direction Addition Length Normalization V = (v 0, v 1, v 2 ) V = X + Y = (x 0 + y 0, x 1 + y 1, x 2 + y 2 ) V = (v 2 0 + v 2 1 + v 2 2) 1/2 U = V / V, hence V = V U ITCS 4120/5120 31 Mathematical Fundamentals
Vectors(contd) Dot (Inner) Product V = X Y = x 0 y 0 + x 1 y 1 + x 2 y 2, Also, V = X Y Cosθ where θ is the angle between X and Y Application Shading calculations Detecting back facing polygons Reflection Vector Calculation ITCS 4120/5120 32 Mathematical Fundamentals
Reflected Ray Calculation V N R θ θ O ON = 1 ON = ( OV. ON) N V N = NR = OV + ( OV. ON) N OR = ON + NR = 2( OV. ON) ON OV ITCS 4120/5120 33 Mathematical Fundamentals
Vector Cross (Outer) Product Application V = X Y i j k = x 0 x 1 x 2 y 0 y 1 y 2 Normal Vector calculations if X and Y are vectors on a polygon (or tangent vectors on a surface, N = X Y is the Normal vector to the surface. ITCS 4120/5120 34 Mathematical Fundamentals
Rays and Intersections Ray Representation Rays generally use a parametric representation May be bounded (eg. line segments) Application x = x 1 + t(x 2 x 1 ) = x 1 + it y = y 1 + t(y 2 y 1 ) = y 1 + jt z = z 1 + t(z 2 z 1 ) = z 1 + kt Ray Tracing and Ray Casting Algorithms Direct Volume Rendering (using Ray Casting) ITCS 4120/5120 35 Mathematical Fundamentals
Ray-Polygon Intersection Check for intersection between ray and the plane containing the polygon Check that the intersection is contained by the polygon Ax + By + Cz + D = 0 (polygon plane equation) Substitution ray equations, t = (Ax 1 + By 1 + Cz 1 + D) (A i + B j + C k) ITCS 4120/5120 36 Mathematical Fundamentals
Ray-Box Intersection t_n1 near2 t_n1 t_n2 t_f1 t_n2 far2 near1 Bounded Volume t_f1 far1 t_f2 t_f2 Intersection Condition Max (Near Inters.) < Min (Far Inters.)? If the maximum of the near intersections is less than the minimum of the far intersections, there an intersection. ITCS 4120/5120 37 Mathematical Fundamentals