Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 2D Transformations 几何变换. 2 What is a transformation? A transformation is an operation that transforms or changes a shape (line, drawing etc.) There.

Similar presentations


Presentation on theme: "1 2D Transformations 几何变换. 2 What is a transformation? A transformation is an operation that transforms or changes a shape (line, drawing etc.) There."— Presentation transcript:

1 1 2D Transformations 几何变换

2 2 What is a transformation? A transformation is an operation that transforms or changes a shape (line, drawing etc.) There are several basic ways you can change a shape:  translation (moving it)  rotation (turning it round)  scaling (making it bigger or smaller). There are others, but we’ll worry about them later.

3 3 2D Geometrical Transformations Translate Rotate Scale Shear

4 4 Translation Consider the arrow below. We may want to move it from position A to position B. A B dxdx dydy x y

5 5 Translate Points We can translate points in the (x, y) plane to new positions by adding translation amounts to the coordinates of the points. For each point P (x, y) to be moved by d x units parallel to the x axis and by d y units parallel to the y axis, to the new point P’(x’, y’ ). The t ranslation has the following form: P(x,y) P’(x’,y’) dxdx dydy

6 6 Translating a line or shape To translate a line, simply translate both of its end points. Translating a shape therefore, simply translate all of the points. The same applies for all transformations.

7 7 Scale Points Points can be scaled (stretched) by s x along the x axis and by s y along the y axis into the new points by the multiplications: We can specify how much bigger or smaller by means of a “scale factor” To double the size of an object we use a scale factor of 2, to half the size of an obejct we use a scale factor of 0.5 P(x,y) P’(x’,y’) x s x  x s y  y y

8 8 We first review the idea of sin and cos for a given angle  : Useful formulas: Rotate Points P x y  l O

9 9 Rotate Points (cont.) Points can be rotated through an angle  about the origin: P(x,y) P’(x’,y’) x x’ y’ y   l O

10 10 Identity transformations Some transformations lead to no change in the shape/drawing Translate(0,0) Rotate(0) Scale(1,1)

11 11 Order of transformations The order in which transformations are applied to a shape is important. Performing a translation followed by a rotation, will give an entirely different drawing to a performing the rotation followed by the same translation.

12 12 Order of transformations

13 13 Order of transformations

14 14 Rotation around local origin At the moment, our rotation is centred around the origin. What is often required is to spin the shape in its original location (in-situ)

15 15 Rotation around local origin This can be achieved by combining two of our existing transformations: Translate the shape to the origin, rotate it the required amount about the origin and translate it back to where it was.

16 16 Local rotation x y dydy dxdx

17 17 Local rotation

18 18 Local rotation y x y

19 19 Local rotation x +d y +d x

20 20 Summary So we have looked at simple transformation of points/lines etc. Next we will look at transformations using matrices.

21 21 2D Transformations with Matrices

22 22 2D Geometrical Transformations Translate Rotate Scale Shear

23 23 Translate Points Recall.. We can translate points in the (x, y) plane to new positions by adding translation amounts to the coordinates of the points. For each point P (x, y) to be moved by d x units parallel to the x axis and by d y units parallel to the y axis, to the new point P’(x’, y’ ). The t ranslation has the following form: P(x,y) P’(x’,y’) dxdx dydy In matrix format: If we define the translation matrix, then we have P’ =P + T.

24 24 Scale Points Points can be scaled (stretched) by s x along the x axis and by s y along the y axis into the new points by the multiplications: We can specify how much bigger or smaller by means of a “scale factor” To double the size of an object we use a scale factor of 2, to half the size of an obejct we use a scale factor of 0.5 P(x,y) P’(x’,y’) x s x  x s y  y y If we define, then we have P’ =SP

25 25 Rotate Points (cont.) Points can be rotated through an angle  about the origin: P(x,y) P’(x’,y’) x x’ y’ y   l O P’ =RP

26 26 Review … Translate: P’ = P+T Scale: P’ = SP Rotate: P’ = RP Spot the odd one out…  Multiplying versus adding matrix…  Ideally, all transformations would be the same.. easier to code Solution: Homogeneous Coordinates

27 27 Homogeneous Coordinates For a given 2D coordinates (x, y), we introduce a third dimension: [x, y, 1] In general, a homogeneous coordinates for a 2D point has the form: [x, y, W] Two homogeneous coordinates [x, y, W] and [x’, y’, W’] are said to be of the same (or equivalent) if x = kx’eg: [2, 3, 6] = [4, 6, 12] y = ky’for some k ≠ 0 where k=2 W = kW’ Therefore any [x, y, W] can be normalised by dividing each element by W: [x/W, y/W, 1]

28 28 Homogeneous Transformations Now, redefine the translation by using homogeneous coordinates: Similarly, we have: Scaling Rotation P’ = S  P P’ = R  P

29 29 Composition of 2D Transformations 1.Additivity of successive translations We want to translate a point P to P’ by T(d x1, d y1 ) and then to P’’ by another T(d x2, d y2 ) On the other hand, we can define T 21 = T(d x1, d y1 ) T(d x2, d y2 ) first, then apply T 21 to P: where

30 30 T(-1,2) T(1,-1) (2,1) (1,3) (2,2) Examples of Composite 2D Transformations

31 31 Composition of 2D Transformations (cont.) 2.Multiplicativity of successive scalings where

32 32 Composition of 2D Transformations (cont.) 3.Additivity of successive rotations where

33 33 Composition of 2D Transformations (cont.) 4.Different types of elementary transformations discussed above can be concatenated as well. where

34 34 Consider the following two questions: 1)translate a line segment P 1 P 2, say, by -1 units in the x direction and -2 units in the y direction. 2). Rotate a line segment P 1 P 2, say by  degrees counter clockwise, about P 1. P 1 (1,2) P 2 (3,3) P’ 2 P’ 1 P 1 (1,2) P 2 (3,3) P’ 2 P’ 1 

35 35 Other Than Point Transformations … Translate Lines:translate both endpoints, then join them. Scale or Rotate Lines:More complex. For example, consider to rotate an arbitrary line about a point P 1, three steps are needed: 1). Translate such that P 1 is at the origin; 2). Rotate; 3). Translate such that the point at the origin returns to P 1. T(-1,-2) R()R() P 1 (1,2) P 2 (3,3) P 2 (2,1) T(1,2) P2P2 P2P2 P1P1 P1P1 P1P1 

36 36 Another Example. Scale Translate Rotate Translate

37 37 Rigid-Body vs. Affine Transformations A transformation matrix of the form where the upper 2  2 sub-matrix is orthogonal, preserves angles and lengths. Such transforms are called rigid-body transformations, because the body or object being transformed is not distorted in any way. An arbitrary sequence of rotation and translation matrices creates a matrix of this form. The product of an arbitrary sequence of rotation, translations, and scale matrices will cause an affine transformation, which have the property of preserving parallelism of lines, but not of lengths and angles.

38 38 Rigid-Body vs. Affine Transformations (cont.) Shear transformation is also affine. Unit cube 45º Scale in x, not in y Rigid- body Transformation Affine Transformation Shear in the x direction Shear in the y direction

39 39

40 40

41 41

42 42 Translate P2->O, T(-1,-1) Rotate R(-90) Shear sHy(-1) Scale S(2,1) Translate O->P2’ T(1,2) M = T(1,2) * S(2,1)*sHy(-1)*R(-90)*T(-1,-1)=

43 43

44 44

45 45 Prove that we can transform a line by transforming its endpoints and then constructing a new line between the transformed endpoints. Answer: S = P + t*(Q- P), 0<= t <= 1 M can be any transform we discussed,then S’ = M*S = M*(P + t*(Q-P)) = M*P + t*(M*Q – M*P)) = P’ + t*(Q’-P’) Q P

46 46 3D Transformations 2D coordinates 3D coordinates x y x y z x z y Right-handed coordinate system:

47 47 3D Transformations (cont.) 1.Translation in 3D is a simple extension from that in 2D: 2.Scaling is similarly extended:

48 48 3D Transformations (cont.) 3.The 2D rotation introduced previously is just a 3D rotation about the z axis. similarly we have: X Y Z

49 49 More Rotations We have shown how to rotate about one of the principle axes, i.e. the axes constituting the coordinate system. There are more we can do, for example, to perform a rotation about an arbitrary axis: X Y Z P 2 (x 2, y 2, z 2 ) P 1 (x 1, y 1, z 1 ) We want to rotate an object about an axis in space passing through (x 1, y 1, z 1 ) and (x 2, y 2, z 2 ).

50 50 Rotating About An Arbitrary Axis Y Z P2P2 P1P1 1). Translate the object by (-x 1, -y 1, -z 1 ): T(-x 1, -y 1, -z 1 ) X Y Z P2P2 P1P1 2). Rotate the axis about x so that it lies on the xz plane: R x (  ) X X Y Z P2P2 P1P1 3). Rotate the axis about y so that it lies on z: R y (  ) X Y Z P2P2 P1P1 4). Rotate object about z by  : R z (  )  

51 51 Rotating About An Arbitrary Axis (cont.) After all the efforts, don’t forget to undo the rotations and the translation! Therefore, the mixed matrix that will perform the required task of rotating an object about an arbitrary axis is given by: M = T(x 1,y 1,z 1 ) Rx(-  )R y (-  ) R z (  ) R y (  ) R x (  )T(-x 1,-y 1,-z 1 ) Finding  is trivial, but what about  ? The angle between the z axis and the projection of P 1 P 2 on yz plane is . X Y Z P2P2  P1P1

52 52 conclusion 1) Left_up 3*3 sub matrix: scale, rotate, shear 2) [p q r]’: translate 3) [l m n] : projection 4) s : Global scale factor

53 53 Viewing in 3D

54 54 Projections Display device (a screen) is 2D…  How do we map 3D objects to 2D space? 2D to 2D is straight forward…  2D window to world.. and a viewport on the 2D surface.  Clip what won't be shown in the 2D window, and map the remainder to the viewport. 3D to 2D is more complicated…  Solution : Transform 3D objects on to a 2D plane using projections

55 55 Projections In 3D…  View volume in the world  Projection onto the 2D projection plane  A viewport to the view surface Process…  1… clip against the view volume,  2… project to 2D plane, or window,  3… map to viewport.

56 56 Projections Conceptual Model of the 3D viewing process

57 57

58 58

59 59 Projections Projections: key terms…  Projection from 3D to 2D is defined by straight projection rays (projectors) emanating from the 'center of projection', passing through each point of the object, and intersecting the 'projection plane' to form a projection.

60 60 Types of projections 2 types of projections  perspective and parallel. Key factor is the center of projection.  if distance to center of projection is finite : perspective  if infinite : parallel

61 61 Perspective v Parallel Perspective:  visual effect is similar to human visual system...  has 'perspective foreshortening' size of object varies inversely with distance from the center of projection.  angles only remain intact for faces parallel to projection plane. Parallel:  less realistic view because of no foreshortening  however, parallel lines remain parallel.  angles only remain intact for faces parallel to projection plane.

62 62 Perspective Projections Any parallel lines not parallel to the projection plane, converge at a vanishing point.  There are an infinite number of these, 1 for each of the infinite amount of directions line can be oriented. If a set of lines are parallel to one of the three principle axes, the vanishing point is called an axis vanishing point.  There are at most 3 such points, corresponding to the number of axes cut by the projection plane.

63 63 Perspective Projections Example:  if z projection plane cuts the z axis: normal to it, so only z has a principle vanishing point, as x and y are parallel and have none. Can categorise perspective projections by the number of principle vanishing points, and the number of axes the projection plane cuts.

64 64 Perspective Projections 2 different examples of a one-point perspective projection of a cube. (note: x and y parallel lines do not converge)

65 65 Perspective Projections Two-point perspective projection:  This is often used in architectural, engineering and industrial design drawings.  Three-point is used less frequently as it adds little extra realism to that offered by two-point perspective projection.

66 66 Perspective Projections Two-point perspective projection:

67 67 Perspective Projections p( x,y,z ) z y Projection plane psps (x s,y s ) C d By similar triangles: p ( x,y,z ) z x Projection plane psps (x s,y s ) C d

68 68 Perspective Projections

69 69 Parallel Projections 2 principle types:  orthographic and oblique. Orthographic :  direction of projection = normal to the projection plane. Oblique :  direction of projection != normal to the projection plane.

70 70 Parallel Projections Orthographic (or orthogonal) projections:  front elevation, top-elevation and side-elevation.  all have projection plane perpendicular to a principle axes. Useful because angle and distance measurements can be made... However, As only one face of an object is shown, it can be hard to create a mental image of the object, even when several view are available.

71 71 Parallel Projections Orthogonal projections:


Download ppt "1 2D Transformations 几何变换. 2 What is a transformation? A transformation is an operation that transforms or changes a shape (line, drawing etc.) There."

Similar presentations


Ads by Google