{"id":35,"date":"2013-11-08T15:46:23","date_gmt":"2013-11-08T15:46:23","guid":{"rendered":"\/\/3dbym.ru\/2013\/11\/addition-and-subtraction\/"},"modified":"2013-11-08T15:46:23","modified_gmt":"2013-11-08T15:46:23","slug":"addition-and-subtraction","status":"publish","type":"post","link":"https:\/\/3dbym.ru\/2013\/11\/addition-and-subtraction\/","title":{"rendered":"Addition and Subtraction"},"content":{"rendered":"

Just like regular numbers, matrices can be added and subtracted. Matrix addition and subtraction are not used much in graphics pro\u00adgramming, but that does not mean they cannot be used in other parts of your game. For instance, if you were building a strategy game, you could use a matrix to represent all of the remaining hitpoints of a group of units. You could add and subtract other matrices to or from this matrix to modify all of your unit\u2019s hitpoints at once, rather than messing with each unit individually. Given two matrixes, A and B, you simply take each element from A and add it to the corresponding element in B. The resulting value goes in the same element in the resultant matrix, called C. For instance, if An is 5 and Bn is 9, Cn would be 14. If we were subtracting A and B, then Cn would be negative 4.<\/p>\n

Going back to the strategy game example, if A11 represented the hitpoints of \u201cunit1\u201d and Bn represented the number of hitpoints when the unit passed through a certain area on the screen, Cn would store the final number of hitpoints for \u201cunit1\u201d. You could then run through the matrix and check for negative values, which would mean the unit is dead or disabled. Matrix addition is associative. This means, given three or more matrices, you can start by adding whichever two you like, without changing the final result. (A + B) + C = A + (B + C). It is also commutative, meaning you can add and subtract matrices in any order without changing the result. A + B = B + A. An illustration of matrix addition is shown in Figure 1.4.<\/p>\n\n\n\n\n
\n

~3<\/p>\n<\/td>\n

\n

5<\/p>\n<\/td>\n

\n

o\u201d<\/p>\n<\/td>\n

\n<\/td>\n\n

~1<\/p>\n<\/td>\n

\n

4<\/p>\n<\/td>\n

\n

7~<\/p>\n<\/td>\n

\n<\/td>\n\n

"3+1<\/p>\n<\/td>\n

\n

5+4<\/p>\n<\/td>\n

\n

0+7~<\/p>\n<\/td>\n

\n<\/td>\n\n

~ 4<\/p>\n<\/td>\n

\n

9<\/p>\n<\/td>\n

\n

7~<\/p>\n<\/td>\n<\/tr>\n

\n

4<\/p>\n<\/td>\n

\n

4<\/p>\n<\/td>\n

\n

8<\/p>\n<\/td>\n

\n

+<\/p>\n<\/td>\n

\n

3<\/p>\n<\/td>\n

\n

4<\/p>\n<\/td>\n

\n

9<\/p>\n<\/td>\n

\n

=<\/p>\n<\/td>\n

\n

4+3<\/p>\n<\/td>\n

\n

4+4<\/p>\n<\/td>\n

\n

8+9<\/p>\n<\/td>\n

\n

=<\/p>\n<\/td>\n

\n

7<\/p>\n<\/td>\n

\n

8<\/p>\n<\/td>\n

\n

17<\/p>\n<\/td>\n<\/tr>\n

\n

9<\/p>\n<\/td>\n

\n

6<\/p>\n<\/td>\n

\n

1<\/p>\n<\/td>\n

\n<\/td>\n\n

0<\/p>\n<\/td>\n

\n

3<\/p>\n<\/td>\n

\n

2<\/p>\n<\/td>\n

\n<\/td>\n\n

9+0<\/p>\n<\/td>\n

\n

6+3<\/p>\n<\/td>\n

\n

1+2<\/p>\n<\/td>\n

\n<\/td>\n\n

9<\/p>\n<\/td>\n

\n

9<\/p>\n<\/td>\n

\n

3<\/p>\n<\/td>\n<\/tr>\n<\/table>\n\n\n
\n

Figure 1.4 An example of matrix addition using 3×3 matrices. Notice how each element of the first matrix is added to the corresponding element of the second matrix and the result is stored in the corresponding element of the final matrix.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n

<\/p>\n

<\/p>\n","protected":false},"excerpt":{"rendered":"

Just like regular numbers, matrices can be added and subtracted. Matrix addition and subtraction are not used much in graphics pro\u00adgramming, but that does not mean they cannot be used in other parts of your game. For instance, if you were building a strategy game, you could use a matrix to represent all of the […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/posts\/35"}],"collection":[{"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/comments?post=35"}],"version-history":[{"count":0,"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/posts\/35\/revisions"}],"wp:attachment":[{"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/media?parent=35"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/categories?post=35"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/tags?post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}