There are two things at the core of this. First is the way Cinema 4D stores Position, Scale and Rotation of an object. It uses a 3x4 Matrix to do this where Vector 0 contains the position and V1-3 contain the orientation in space. These three vectors are usualy at 90° angles to each other and of length 1. To create an own matrix that aligns the object correctly you can use the existing polygon normal (a normal is a vector with the length 1), a second normal calculated by using one of the points of the polygon and the polygon center, and as the third normal you use the cross product to create it from the two you already know. This cross product is the second element important part.
All in all it is just a bit of vector and matrix calculation and you can read up on it in any Highschool math book.
If you want to go further read up on analytical geometry. In general this kind of knowledge is very helpful if you want to script in 3D applications.
Edit: Disclaimer, i learned this stuff at the polytechnical, but i had to relearn it when i started doing 3D.