How did the first matrix derived? Also the second one?

The picture came from here. Part Five: Quaternions