Your SlideShare is downloading. ×
0
Matrix 2 d
Matrix 2 d
Matrix 2 d
Matrix 2 d
Matrix 2 d
Matrix 2 d
Matrix 2 d
Matrix 2 d
Matrix 2 d
Matrix 2 d
Matrix 2 d
Matrix 2 d
Matrix 2 d
Matrix 2 d
Matrix 2 d
Matrix 2 d
Matrix 2 d
Matrix 2 d
Matrix 2 d
Matrix 2 d
Matrix 2 d
Matrix 2 d
Matrix 2 d
Matrix 2 d
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Matrix 2 d

138

Published on

learn more at http://www.filestack.in

learn more at http://www.filestack.in

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
138
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 2D Transformations with Matrices
  • 2. Matrices a1, 2 a2 , 2 a1,3 a2 ,3 a3,1 A a1,1 a2,1 a3, 2 a3 , 3 • A matrix is a rectangular array of numbers. • A general matrix will be represented by an upper-case italicised letter. • The element on the ith row and jth column is denoted by ai,j. Note that we start indexing at 1, whereas C indexes arrays from 0.
  • 3. Matrices – Addition • Given two matrices A and B if we want to add B to A (that is form A+B) then if A is (n m), B must be (n m), Otherwise, A+B is not defined. • The addition produces a result, C = A+B, with elements: Ci , j Ai , j Bi , j 1 2 5 6 1 5 2 6 6 8 3 4 7 8 3 7 4 8 10 12
  • 4. Matrices – Multiplication • Given two matrices A and B if we want to multiply B by A (that is form AB) then if A is (n m), B must be (m p), i.e., the number of columns in A must be equal to the number of rows in B. Otherwise, AB is not defined. • The multiplication produces a result, C = AB, with elements: m Ci , j aik bkj k 1 (Basically we multiply the first row of A with the first column of B and put this in the c1,1 element of C. And so on…).
  • 5. Matrices – Multiplication (Examples) 2 6+ 6 3+ 7 2=44 2 6 7 6 8 44 76 4 5 8 3 3 55 95 9 2 3 2 6 66 96 2 6 4 5 6 8 3 3 2 6 Undefined! 2x2 x 3x2 2!=3 2x2 x 2x4 x 4x4 is allowed. Result is 2x4 matrix
  • 6. Matrices -- Basics • Unlike scalar multiplication, AB ≠ BA • Matrix multiplication distributes over addition: A(B+C) = AB + AC • Identity matrix for multiplication is defined as I. • The transpose of a matrix, A, is either denoted AT or A’ is obtained by swapping the rows and columns of A: A a1,1 a2,1 a1, 2 a2 , 2 a1,3 a2 , 3 A' a1,1 a1, 2 a2,1 a2 , 2 a1,3 a2 ,3
  • 7. 2D Geometrical Transformations Translate Rotate Shear Scale
  • 8. 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 dx units parallel to the x axis and by dy units parallel to the y axis, to the new point P’(x’, y’ ). The translation has the following form: x' x d x y' P’(x’,y’) dy dx P(x,y) y dy In matrix format: x' dx y' If we define the translation matrix T x y dy dx dy , then we have P’ =P + T.
  • 9. Scale Points Points can be scaled (stretched) by sx along the x axis and by sy 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 x' s x x y y' s y y P(x,y) sy y P’(x’,y’) x' y' sx x If we define S x sx 0 0 , then we have P’ =SP sy sx 0 0 sy x y
  • 10. Rotate Points (cont.) Points can be rotated through an angle about the origin: | OP' | | OP | l P’(x’,y’) x' | OP' | cos( ) l cos cos x cos l cos( ) y y’ l sin sin x’ O y sin P(x,y) l x x' y ' | OP' | sin( l cos sin x sin ) l sin( l sin cos ) cos sin x y' sin cos y y cos P’ =RP
  • 11. Review… • Translate: • Scale: • Rotate: P’ = P+T P’ = SP P’ = RP • Spot the odd one out… – Multiplying versus adding matrix… – Ideally, all transformations would be the same.. • easier to code • Solution: Homogeneous Coordinates
  • 12. 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’ y = ky’ W = kW’ for some k ≠ 0 eg: [2, 3, 6] = [4, 6, 12] where k=2 Therefore any [x, y, W] can be normalised by dividing each element by W: [x/W, y/W, 1]
  • 13. Homogeneous Transformations Now, redefine the translation by using homogeneous coordinates: x' x' x y' y 0 dx x 0 1 dy y 1 dy 1 y' dx 0 0 1 1 P' T P Similarly, we have: Scaling Rotation x' sx 0 0 x x' cos sin 0 x y' 0 sy 0 y y' sin cos 0 y 1 0 0 1 1 0 0 1 1 R P P’ = S P 1 P’ =
  • 14. Composition of 2D Transformations 1. Additivity of successive translations We want to translate a point P to P’ by T(dx1, dy1) and then to P’’ by another T(dx2, dy2) P ' ' T (d x 2 , d y 2 ) P' T (d x 2 , d y 2 )[T (d x1 , d y1 ) P] On the other hand, we can define T21= T(dx1, dy1) T(dx2, dy2) first, then apply T21 to P: P' ' T21P where T21 T (d x 2 , d y 2 )T (d x1 , d y1 ) 1 0 d x 2 1 0 d x1 1 0 d x1 d x 2 0 1 d y 2 0 1 d y1 0 0 1 0 0 1 0 1 d y1 d y 2 0 0 1
  • 15. Examples of Composite 2D Transformations T(-1,2) (1,3) T(1,-1) (2,2) (2,1) 1 0 T21 1 0 1 0 0 1 0 1 0 1 1 1 0 0 0 1 1 0 0 1 0 0 1 2 1
  • 16. Composition of 2D Transformations (cont.) 2. Multiplicativity of successive scalings P' ' S ( s x 2 , s y 2 )[S ( s x1 , s y1 ) P] [ S ( s x 2 , s y 2 ) S ( s x1 , s y1 )]P S 21 P where S 21 S ( s x 2 , s y 2 ) S ( s x1 , s y1 ) sx 2 0 0 s x1 0 0 0 sy2 0 0 s y1 0 0 0 1 0 0 1 s x 2 * s x1 0 0 s y 2 * s y1 0 0 0 0 1
  • 17. Composition of 2D Transformations (cont.) 3. Additivity of successive rotations P' ' R( 2 )[R( 1 ) P] [ R( 2 ) R( 1 )]P R21P where R21 R( 2 ) R( 1 ) cos sin 0 cos( sin( 2 2 2 2 0 sin cos 0 ) 1) 1 2 2 0 cos 0 sin 1 0 sin( 2 cos( 2 0 1 1 ) 1) 1 sin cos 0 0 0 1 1 1 0 0 1
  • 18. Composition of 2D Transformations (cont.) 4. Different types of elementary transformations discussed above can be concatenated as well. P' R( )[T (d x , d y ) P] [ R( )T (d x , d y )]P MP where M R ( )T ( d x , d y )
  • 19. Consider the following two questions: 1) translate a line segment P1 P2, say, by -1 units in the x direction and -2 units in the y direction. P2(3,3) P’2 P1(1,2) P’1 2). Rotate a line segment P1 P2, say by degrees counter clockwise, about P1. P’2 P2(3,3) P1(1,2) P’1
  • 20. 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 P1, three steps are needed: 1). Translate such that P1 is at the origin; 2). Rotate; 3). Translate such that the point at the origin returns to P1. P2 P2(3,3) T(-1,-2) P2 R( ) P2(2,1) P1(1,2) P1 P1 T(1,2) P1
  • 21. Another Example. Translate Translate Rotate Scale
  • 22. Order Matters! As we said, the order for composition of 2D geometrical transformations matters, because, in general, matrix multiplication is not commutative. However, it is easy to show that, in the following four cases, commutativity holds: 1). Translation + Translation 2). Scaling + Scaling 3). Rotation + Rotation 4). Scaling (with sx = sy) + Rotation just to verify case 4: M 1 S ( s x , s y ) R( ) M2 sx 0 0 sy 0 cos 0 sin 0 0 1 s x * cos s y * sin 0 R( ) S ( s x , s y ) sin cos cos sin 0 0 0 0 1 0 s x * sin s y * cos 0 0 0 1 if sx = sy, M1 = M2. sin cos 0 sx 0 0 sy 0 0 0 s x * cos s x * sin 0 0 1 0 0 1 s y * sin s y * cos 0 0 0 1
  • 23. Rigid-Body vs. Affine Transformations A transformation matrix of the form r11 r12 tx r21 r22 ty 0 0 1 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.
  • 24. Rigid-Body vs. Affine Transformations (cont.) Rigid- body Transformation Affine Transformation 45º Unit cube Scale in x, not in y Shear transformation is also affine. Shear in the x direction 1 SH x a 0 0 1 0 0 0 1 Shear in the y direction 1 SH y 0 0 b 1 0 0 0 1

×