Jump to content

GPIGuide - Matrix Multiplication

From EDM2

Reprint Courtesy of International Business Machines Corporation, © International Business Machines Corporation

GPI Guide and Reference
  1. How to Use the GPI Guide and Reference
  2. Graphics Functions
  3. Data Types
  4. Graphics Orders
  5. Graphics Orders Data Types
  6. Errors
  7. Area and Polygon Primitives
  8. Bit Maps
  9. Creating and Drawing Retained Graphics
  10. Character String Primitives
  11. Clipping and Boundary Determination
  12. Color and Mix Attributes
  13. Correlation
  14. Coordinate Spaces and Transformations
  15. Editing Retained Graphics and Graphics Segments
  16. Fonts
  17. Graphics Attributes
  18. Line and Arc Primitives
  19. Marker Primitives
  20. Matrix Multiplication
  21. Metafiles
  22. Print Job Submission and Manipulation
  23. Presentation Spaces and Device Contexts
  24. Paths
  25. Regions
  26. Notices
  27. Glossary

To show how matrix multiplication is implemented, here are two matrixes:

    ┌         ┐         ┌         ┐
    │ a  b  c │         │ j  k  l │
    │ d  e  f │    *    │ m  n  o │
    │ g  h  i │         │ p  q  r │
    └         ┘         └         ┘

The multiplication of these two matrixes produces a value for each of the nine elements of the resulting matrix:

    ┌                              ┐
    │ element1  element2  element3 │
    │ element4  element5  element6 │
    │ element7  element8  element9 │
    └                              ┘

To produce element 1 of the matrix, element a is multiplied by element j, element b is multiplied by element m, and element c is multiplied by element p. That is:

element1 = (a x j) + (b x m) + (c x p)

To produce element 2 of the matrix, element a is multiplied by element k, element b is multiplied by element n, and element c is multiplied by element q. To produce element 3 of the matrix, elements a, b, and c are multiplied by their corresponding elements (l, o, and r) in the third vertical line of the second matrix. To produce element 4 of the matrix, you move down a row in the first matrix. That is, element d is multiplied by element j, element e is multiplied by element m, and element f is multiplied by element p. You continue the multiplication in this way until each of the nine elements has a value. The complete workings for this example are as follows:

element1 = (a x j) + (b x m) + (c x p)
element2 = (a x k) + (b x n) + (c x q)
element3 = (a x l) + (b x o) + (c x r)
element4 = (d x j) + (e x m) + (f x p)
element5 = (d x k) + (e x n) + (f x q)
element6 = (d x l) + (e x o) + (f x r)
element7 = (g x j) + (h x m) + (i x p)
element8 = (g x k) + (h x n) + (i x q)
element9 = (g x l) + (h x o) + (i x r)

Note that if the order of the two matrixes is reversed, the results of the multiplication are different.

Here is a simple example in which an object is scaled by a factor of 3, and then translated by (5,4):

    ┌         ┐         ┌         ┐          ┌         ┐
    │ 3  0  0 │         │ 1  0  0 │          │ 3  0  0 │
    │ 0  3  0 │    *    │ 0  1  0 │     =    │ 0  3  0 │
    │ 0  0  1 │         │ 5  4  1 │          │ 5  4  1 │
    └         ┘         └         ┘          └         ┘

You can multiply together as many transformation matrixes as you require.