There are two coordinate systems. We know the 3D coordinates of the origin and the 3D vectors of the axes of the second coordinate system with respect to the first coordinates s
I think the change of basis could help youWiki Link. Its quite easy to implement.