2 D Geometry points and polygons A point










![Let the point (x, y) be a row vector [x y]: x' = ax Let the point (x, y) be a row vector [x y]: x' = ax](https://slidetodoc.com/presentation_image_h2/745e4d84d5051d8829acdc8bf3b1f6ea/image-11.jpg)
![Homogeneous Coordinates Let the point (x, y) be a row vector [x y 1]: Homogeneous Coordinates Let the point (x, y) be a row vector [x y 1]:](https://slidetodoc.com/presentation_image_h2/745e4d84d5051d8829acdc8bf3b1f6ea/image-12.jpg)





- Slides: 17
2 D Geometry - points and polygons A point in 2 D is represented by two real numbers (X, Y) Y X A line segment is represented by its two end points (X 1, Y 1) (X 2, Y 2), or a 2 x 2 matrix [ ] X 1 Y 1 X 2 Y X CG Page: 1 東吳資訊科學 江清水
A polygon is represented by an list of points (X 1, Y 1), (X 2, Y 2), . . . (Xn, Yn) or a [ ] X 1 Y 1 n x 2 matrix : : Xn Yn For example, a triangle is represent by X 1 Y 1 X 2 Y 2 X 3 Y 3 [ ] Y X CG Page: 2 東吳資訊科學 江清水
Object transformation and Coordinates System transformation Object transformation is different from the coordinates system transformation Y (2, 4) 2 1 (2, 2) 1 2 CG Page: 3 (6, 2) 8 X 東吳資訊科學 江清水
Object Transformation Y Scale (1/2) about the origin X Y Translation (2, 1) X Rotation (p/2) counter clock wise about the origin Y X CG Page: 4 東吳資訊科學 江清水
Coordinates system transformation Y* Scale (1/2) about the origin 2 1 Translation (2, 1) X* 3 Y X Rotation (p/2) counter clock wise about the origin Y X If not described explicitly, transformation always means object transformation CG Page: 5 東吳資訊科學 江清水
2 D Translations There are 3 "basic" transformations: (1) Translation (2) Scaling (3) Rotation A series of transformations can be combined (concatenated) into one. (1) Translation : T(Tx, Ty) Y (x', y') Ty (x, y) Tx X CG Page: 6 東吳資訊科學 江清水
(2) Scaling (about the origin) : S(Sx, Sy) Y Y (x', y') (x, y) X X • What about "Mirror Images"? S(-2, -1) • How do we avoid distortion? • What happens when the scale factor equal to zero? CG Page: 7 東吳資訊科學 江清水
(3) Rotation (about the origin counterclockwise) : Y (x', y') (x, y) q a x y x' y' = = X R cos a R sin a R cos(a + q) = R(cos a cos q - sin a sin q) R sin(a + q) = R(sin a cos q + cos a sinq) So, x ' = xcosq - ysinq y ' = xsinq + ycosq CG Page: 8 東吳資訊科學 江清水
Concatenation -- A series of transformations can be combined (concatenated) into one. Example: scaling about arbitrary point. Y (x, y) (a, b) X 1. Translate so that point (a, b) becomes the temporary origin: x 1 = x - a y 1 = y - b 2. Scale to the correct size: x 2 = Sx*x 1 y 2 = Sy*y 1 3. Translate again to restore the coordinates of (a, b): x 3 = x 2 + a y 3 = y 2 + b CG Page: 9 東吳資訊科學 江清水
Algebraic representations for transformations are very limited: (1) A special procedure is need for each basic transformation and other known concatenated forms. (2) It is difficult to provide general transformation capabilities in algebraic form in the computer. (3) How can one find the inverse of a concatenated equation (to restore the original position, for example)? CG Page: 10 東吳資訊科學 江清水
Let the point (x, y) be a row vector [x y]: x' = ax + by and y' = cx + dy can be expressed in the matrix equation: [x' y'] = [x y] * [ ] 2 x 2 Let P' = [x' y'] and P = [x y], this becomes the matrix equation: P' = P * T where P' =[x' y'] , a c P = [x y] , T = [ b d ] Consider three basic transformations, can we find a "T" for each? • What about translations? X'=X+Tx, Y'=Y+Ty No, P' =[x' y']=[x y] [ ]+[T 1 0 0 1 x Ty]=P*T+Q • What about scaling? X'=Sx*X, Y'=Sy*Y Yes, P' =[x' y']=[x y] [ S 0 ] =P*T x y • What about rotation? x'=xcosq-ysinq, y'=xsinq+ycosq Yes, P' =[x' y']=[x y] CG Page: 11 [ cosq -sinq cosq ] 東吳資訊科學 江清水
Homogeneous Coordinates Let the point (x, y) be a row vector [x y 1]: x' = ax + by + e and y' = cx + dy + f can be expressed in the matrix equation: [x' y' 1] = [x y 1] [ ] 3 x 3 This becomes the matrix equation P' = P * T where P'=[x' y' 1], P= [x y 1], T= [ ] Now, can we find a "T" for each transformation? • What about translations? • What about scaling? Yes, T= [ [ • What about rotation? Yes, T= CG Page: 12 [ ] ] ] 東吳資訊科學 江清水
To check, what should the matrix be if we: (1) translate by (0, 0) ? P'=P* [ ]=P*[ ]=P (2) scale by (1, 1) ? P'=P* [ ]=P*[ ]=P (3) rotate by 0 o ? P'=P* [ ]=P*[ ]=P (4) rotate by 90 o ? (x', y') = (0, 1) P'=[x' y' 1]=[x y 1] (x, y) = (1, 0) =[1 0 1]* [ [ ] ]=[0 1 1] Draw the pictures and find the new vertices of the triangle for the following transformations (See the figure below) : Y A(2, 2) C(4, 1) B (2, 1) CG Page: 13 X 東吳資訊科學 江清水
(5) translate A by (2, 1). Y A (2, 2) C (4, 1) X B (2, 1) (6) translate A by (-2, 1). Y A (2, 2) C (4, 1) X B (2, 1) (7) scale A by (2, 1). Y A (2, 2) C (4, 1) X B (2, 1) (8) scale A by (-1, 1). Y A (2, 2) B (2, 1) CG Page: 14 C (4, 1) X 東吳資訊科學 江清水
(9) scale A by (1, 0). Y A (2, 2) B (2, 1) C (4, 1) X (10) scale A by (0, 0). Y A (2, 2) B (2, 1) C (4, 1) X (11) rotate A by 0 o. Y A (2, 2) B (2, 1) C (4, 1) X o. (12) rotate A by 90 Y A (2, 2) B (2, 1) CG Page: 15 C (4, 1) X 東吳資訊科學 江清水
Composite 2 D Transformation Concatenation is easy now. Consider our scaling example: Example: We want to reduce the size or the box, without changing the position of point (a, b) Y (x, y) (a, b) X Functional form and matrix form for each transformations: (1) translate: T(-a, -b) (2) scale : S(Sx, Sy) (3) translate: T(a, b) CG Page: 16 東吳資訊科學 江清水
Combining the matrix equations: P 3 =P 2* T (-a, -b)=(P 1*S(Sx, Sy) )*T(a, b) =P*T(-a, -b) *S(Sx, Sy)*T(a, b) Multiply the matrices : Now, the matrix equation is : or, in algebraic form : Thus, a single 3 x 3 matrix can represent any combination of basic transformations in a simple form. CG Page: 17 東吳資訊科學 江清水