Glad you got an approach working. You may not care about the other method then. But just in case you’re curious…
Ok, now subtract the center of the sphere from that, and normalize the result. So you have a unit vector pointing from the center of the sphere to the point on the sphere. That is:
w = normalize( (x,y,z) - center );
var u = new THREE.Vector3(0,0,1);
u = u.crossSelf(w);
var v = new THREE.Vector3(0,0,0)
var v = v.cross(w,u);
Not sure what "crossSelf does, but you want:
v = normalize( cross( w, (0,0,1) ) ); (assuming a right handed coordinate system).
u = cross( v,w );
I’m just not sure what you mean by the last step - stuffing them into a matrix.
Stuff them in the upper-left 3x3 of your 4x4 matrix, like this:
u_x u_y u_z 0
v_x v_y v_z 0
w_x w_y w_z 0
0 0 0 1
As you can see, if you premultiply this by a vector (1,0,0), you get “u”. If you premultiply this by a vector (0,1,0), you get “v”. Similarly for (0,0,1) -> w. You’ve just built a basis change matrix (i.e. the rotation matrix), without having to mess with any trig!
Now slam (x,y,z) in the last column (your translation), and you’re done!
By the way, the one bit of error checking you’ll want to add to the above is if “cross( w, (0,0,1) )” is (0,0,0) (i.e. the length is 0), then w and (0,0,1) are colinear. – in this case just chose another arbitrary “up vector”. If (0,0,1) points toward the north pole of your sphere, you’d only do this for points that are exactly on the north or south poles.