The theory sounds really good and interesting but the actual programming part is what is missing.
Too bad that it seems to be so hard to find practical examples or tutorial regarding this problem.
its not, actually. i linked an article for you immediately after my first post.
Also, this is not "theory," what i gave you was a practical technique. Theory would have been trying to explain how you can do N-dimensional rotations and translations using Matrix math...
As it has been noted, you are asking just for code but even if we give it to you, how will you know what to change to make it work for you, when you haven't fully understood the concepts?
Thanks @ BCullis and slicer4ever for their responses, as well