# 2x2 matrices

8 replies to this topic

### #1squint

New Member

• Members
• 14 posts

Posted 26 February 2011 - 12:14 AM

A 2D matrix that contains only a rotation cannot have a form other than (cos(a), sin(a), -sin(a), cos(a)) and that means I should only be storing 2 numbers - the other two are implicit. Not only does that improve my chances of hitting the cache with complex data objects, it means there are two less places for rounding errors to mess everything up. So, my 2D physics engine will now be storing orientations as two floats instead of four.

Is this:
a) Neat
b) Old hat
c) Wrong

### #2Reedbeta

DevMaster Staff

• 5340 posts
• LocationSanta Clara, CA

Posted 26 February 2011 - 12:43 AM

Well, for 2D, you could do it with a single number - the angle.

But if you want to avoid trigonometric functions, it's certainly possible to do it by storing only the first row of the matrix, reconstructing the second row on demand. This is sort of the 2D analogue of using quaternions instead of 3x3 rotation matrices. In fact, the first row of a 2D rotation matrix could be thought of as real and imaginary parts of a normalized complex number, which represents rotation in 2D in the same way that quaternions represent rotation in 3D.
reedbeta.com - developer blog, OpenGL demos, and other projects

### #3rouncer

Senior Member

• Members
• 2757 posts

Posted 26 February 2011 - 12:59 AM

hehe
you used to be able to fit a game on a disk, then you used to be able to fit a game on a cd, then you used to be able to fit a game on a dvd, now you can barely fit one on your harddrive.

### #4EricTheRed

New Member

• Members
• 6 posts

Posted 26 February 2011 - 02:56 AM

There are some other advantages as well such as being to interpolate between angles in the same way as 3D quaternions.
It's not what you know, it's what other people think you know.
Just hope you don't get quizzed on it.
Game engine design tutorials

### #5.oisyn

DevMaster Staff

• Moderators
• 1842 posts

Posted 26 February 2011 - 01:01 PM

EricTheRed said:

There are some other advantages as well such as being to interpolate between angles in the same way as 3D quaternions.
Actually, there is no advantage. If you know your matrix is orthonormal (ie., only contains a rotation), it's just as easy to interpolate angles as with only storing the first row.
-
Currently working on: the 3D engine for Tomb Raider.

### #6squint

New Member

• Members
• 14 posts

Posted 26 February 2011 - 03:02 PM

or, infact, just as hard - unless you all know something I don't I still need trig to interpolate a rotation matrix?

### #7.oisyn

DevMaster Staff

• Moderators
• 1842 posts

Posted 27 February 2011 - 02:43 PM

The point in case was that you could interpolate like quaternions. To interpolate quaternions you also need trigonometric functions
-
Currently working on: the 3D engine for Tomb Raider.

### #8squint

New Member

• Members
• 14 posts

Posted 27 February 2011 - 11:29 PM

Well, atleast the inverse operator is nice and fast :yes:

### #9}:+()___ (Smile)

Member

• Members
• 169 posts

Posted 28 February 2011 - 12:47 PM

Well, inverse operator for angle is nice and fast too.
Sorry my broken english!

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users