In a previous post I showed how complex numbers are useful when rotating co-ordinates and since then I’ve hard coded several geometrical translation and rotation routines that have been crude, but functional in Mathematica. Nothing too complex, but a nice little achievement, working with matrices and manipulations.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
tx = 2; ty = 4; tz = 6; translateM = ( { {1, 0, 0, tx}, {0, 1, 0, ty}, {0, 0, 1, tz}, {0, 0, 0, 1} } ); roll = 45 Degree; pitch = 45 Degree; yaw = 45 Degree; rollM = ( { {Cos[roll], -Sin[roll], 0, 0}, {Sin[roll], Cos[roll], 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1} } ); pitchM = ( { {1, 0, 0, 0}, {0, Cos[pitch], -Sin[pitch], 0}, {0, Sin[pitch], Cos[pitch], 0}, {0, 0, 0, 1} } ); yawM = ( { {Cos[yaw], 0, Sin[yaw], 0}, {0, 1, 0, 0}, {-Sin[yaw], 0, Cos[yaw], 0}, {0, 0, 0, 1} } ); Delete[aMod.translateM.rollM.pitchM.yawM , {4}] // MatrixForm |

But the scary thing about a big program like Mathematica, is that it has lots of built in functions that whilst incredibly well documented, you have to be aware that they exist before you can start to search for them.

The transformation matrices scripted above, can be automated using some of the inbuilt functions in Mathematica 9. So for example if I wanted to rotate some co-ordinates about the z-axis the syntax is quite straightforward and can be taken from the documentation. Rotating 4 co-ordinates (a) around the z axis (b) to give the newly updated co-ordinates (c).

1 2 3 |
a = {{0, r, 0}, {r, 0, 0}, {0, -r, 0}, {-r, 0, 0}} b = RotationTransform[-Pi/4, {0, 0, 1}] c = %[a] |

There are quite a few neat and compact examples over on the documentation website if you’re interested.

I personally struggle with Mathematica at times, not because the documentation is poor, but because the scope is so vast. But with helpful sites such as Stack Exchange or the Wolfram Community Page I’m sure I’ll start to work my way through some of the more hardcore functions given time.