2x2 matrices

A4956f14412244c2942ff6746b81fc04
0
squint 101 Feb 26, 2011 at 00:14

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

8 Replies

Please log in or register to post a reply.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 168 Feb 26, 2011 at 00:43

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.

Fd80f81596aa1cf809ceb1c2077e190b
0
rouncer 104 Feb 26, 2011 at 00:59

hehe

2d727e94e347cd5d1ef860a48d6b0bd2
0
EricTheRed 101 Feb 26, 2011 at 02:56

There are some other advantages as well such as being to interpolate between angles in the same way as 3D quaternions.

340bf64ac6abda6e40f7e860279823cb
0
_oisyn 101 Feb 26, 2011 at 13:01

@EricTheRed

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.

A4956f14412244c2942ff6746b81fc04
0
squint 101 Feb 26, 2011 at 15:02

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

340bf64ac6abda6e40f7e860279823cb
0
_oisyn 101 Feb 27, 2011 at 14:43

The point in case was that you could interpolate like quaternions. To interpolate quaternions you also need trigonometric functions :)

A4956f14412244c2942ff6746b81fc04
0
squint 101 Feb 27, 2011 at 23:29

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

6eaf0e08fe36b2c23ca096562dd7a8b7
0
__________Smile_ 101 Feb 28, 2011 at 12:47

Well, inverse operator for angle is nice and fast too.