Magneto Calibration understand a source code (MagMASTER)

Hello Guys,
I’m trying to devellop a magneto calibration, i already found an open source code which was develloped for arduino. the name of the program is the magmaster which was develloped by yury.

i can’t understand the logic of this code specially that he’s using a sort of a rotation matrix, i loocked how can we create this matrix but he’s logique is very different from what i founded.

whats i founded was that we creat it from cosin(teta) and vectors

But what he did was to create directly the matrix from his vectors, the vector was creted from the coordinate in 0 degres and 180 degree on different axes +x ,-x ,+y,-y,+z,-z

this is the part of the code:


i really need help to understand this and sorry for my english

sorry for my english.