Jump to content
  • Advertisement
Sign in to follow this  
krum

operator+ and operator- for Matrix classes: do they make sense?

This topic is 4599 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When and why would you ever want to add, subtract, or even divide a matrix for a game engine? I'm rewriting my engine and I've encountered these operators in the old code, but I've never used them. Does it make sense? Maybe they should be private and unimplemented to make a point? Thoughts?

Share this post


Link to post
Share on other sites
Advertisement
division isn't even a proper matrix opperator. unless you interprit it as a multiplication by an inverse. addition is a common opperation mathematically. but usually when it's used, the person will do the addition by hand and present the final matrix in singular form for the computer.

Share this post


Link to post
Share on other sites
Ax=cx, Ax-cx=0, Ax-cIx=0, (A-cI)x=0 where A is a matrix, I is the identity matrix, c is a scalar constant, x is an unknown vector and 0 is the 0 vector. Solve that for x and you get the eigenvectors of A. Extracting the axis and angle from a rotation matrix is another place you use the differance of two matrices in the calculation.

Addition and subtraction of a scalar from a matrix is a bit more unusual. It is really of no use in linear algebra and isn't even defined in linear algebra. Packages like MatLab do define it though because not all two dimensional arrays are matrices in a linear algebra sense. An example is scaling and translating a height field. You use perlin noise or some function generating numbers in the interval [0,1] or [-1,1] and you want numbers in the interval [100,200] or something. So you have to multiply and add each element of the array. Adding or subtracting a scalar to/from an array is a compact way to specify that rather than requiring the user to code a loop.

Share this post


Link to post
Share on other sites
A couple more examples where these operators can be useful: lerping of matrices (addition, and division by a scalar), integration of a rotation matrix (addition, and multiplication by a scalar), and matrix inversion (division by the determinant). There may be some compelling argument to the contrary that I'm not aware of, but I would go ahead and implement all the (basic) operators that are defined mathematically for matrices, as it's likely you'll end up using them all at some time or another.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!