# How to compute a transformation matrix that describes each position and rotation on a sphere?

I am having an issue constructing my transformation matrices, for this sphere problem. I know the 3d coordinate of the center, and the radius of, the sphere.

Since I know the radius and center of the sphere, it's easy to compute all positions on the sphere, but I'm not sure how I should compute the rotation matrix?

Each point has to be rotated such that it points toward the object, and the only thing that tells me the orientation of the vector is the difference between the 3d point on sphere and the 3d point of the object.. But one vector doesn't seem enough to construct a whole rotation matrix?...

Could I extract a rotation matrix, that "tells" the point how it should be rotated to look at the object?

## 1 Answer

Indeed, you need an additional orientation hint for this to work.

It is quite common to use an “up” vector in addition to the view vector that you computed. Most 3D libraries have some kind of “lookat” function: Transform.LookAt in Unity3D, glm::lookAt in glm, or the deprecated gluLookAt in ancient OpenGL.

Note that if the “up” vector is constant or only depends on the position, you will have discontinuities in the resulting transformation. This is mathematically unavoidable. One possibility is to use e.g. (0,0,1) as a constant “up” vector, and just disallow the viewer from being exactly in (0,0,1) or (0,0,-1).

• I did read a bit about the up vector.. which might help me?.. I am not using any form of 3d library, so i have to compute it using mathematics. – Lamda Apr 23 '16 at 10:41
• It seems like the up vector should be perpendicular to the my orient vector?.. but it does not seem like that 0,0,1 is always perpendicular to that.. – Lamda Apr 23 '16 at 10:47
• I am sure i understand the problem.. Could you demonstrate with an illustration? – Lamda Apr 23 '16 at 11:08
• Will gimbal lock be an issue here? – Lamda Apr 23 '16 at 11:21
• No, the up vector is just a general hint, it does not have to be perpendicular to your view vector. It just has to be non-collinear. Gimbal lock is related to this, but probably not an issue for you. – sam hocevar Apr 23 '16 at 11:27