I\'ve got a longitude and latitude and want to convert this to a quaternion and wondering how I can do this? I want to use this, because I\'ve got an app which projects the
Latitude and longitude aren't enough to describe a quaternion. Latitude and longitude can describe a point on the surface of a 3d sphere. Let's say that's the point whose normal points directly out through the screen. You still have a degree of freedom left. The sphere can spin around the normal vector of the point specified by lat-lon. If you want a quaternion that represents the orientation of the sphere, you need to fully specify the rotation.
So let's say that you want to keep the north-pole of the sphere pointed upward. If the north pole is aligned with the object's +z axis and 'up' on the screen is aligned with the world's +y axis, and then you want to rotate the sphere so that point R on the surface of the sphere is pointed directly out at the screen (where R is found using lat-lon to euclidean as you mentioned in your comment), then you create the rotation matrix as follows.
You want object's R to align with the world's +z (assuming an OpenGL-like view-coordinate system) and you want object's +z to align with world's +y (as close as possible). We need the third axis; so we normalize R and then find: P = crossP([0 0 1]^T,R). We normalize P and then enforce orthogonality onto the second axis: Q = crossP(R,P). Finally, normalize Q. Now we have 3 orthogonal vectors P, Q, R that we want to align with the world's x,y,z respectively.
I'm assuming that P, Q, and R are column vectors; so to create a transformation matrix, we just stick 'em together: M = [P Q R]. Now M is the matrix that would transform a point in world coordinates into object coordinates. To go the opposite direction, we find the inverse of M. Fortunately, when the columns of a matrix are orthonormal, the inverse is the same as the transpose. So we get:
[ P^T ]
M^-1 = M^T = [ Q^T ]
[ R^T ]
From that, if you need, you can find a quaternion using matrix to quaternion conversion. And then you can interpolate between quaternions using slerp or your method of choice.