Find yaw/pitch of one vector relative to another vector.
I've reworded my initial post to hopefully shed more light on what I'm attempting to accomplish.
This is a 3D problem that I am trying to solve. I have a scenario where I need to be able to travel in a direction (v) while maintaining a line of sight with a point in 3D space (u). However, one restriction is that the line of sight must be confined to a fixed viewing area. For instance, the camera traveling in the v direction is restricted so that it can only tilt up/down 45 degrees and turn left/right 50 degrees. If the point in 3D space is too far behind the camera, then the camera will no longer be able to point in the precise direction of the point, but it would point in the general direction of the point.
I've been tackling this problem for some time now, and conceptually, it is very easy to understand. The most confusing aspect to me is how to accurately calculate the angles for the yaw and pitch.
What I've done so far....
To determine the values for the camera's direction vector, I am taking the known yaw and pitch angles (my current heading) and calculating the x, y, z coordinates onto a unit sphere.
v.x = cos(alpha) * cos(beta);
v.y = sin(beta);
v.z = sin(alpha) * cos(beta);
This produces my direction vector in an already normalized form. I then take the point in space that I'm looking at and subtract my current position to create the vector, u, to the point in 3D space. I am not normalizing this vector.
Once I've created these two vectors, I attempt to get the yaw and pitch angles between them. To do this, I create a new vector, w, by subtracting u from v (so w = v  u). I then normalize that vector. I know that the yaw angle will be the asin of the y component of the w vector.
yaw = asin(w.y)
That yaw value can then be plugged in to my sphere equation to give pitch. Of course, I'll have to account for situations where cos(yaw) equals 0.
pitch = acos(w.x / cos(yaw))
However, the results that I'm seeing don't match what I am expecting to see. As an example... in some cases, a yaw angle of 82 might be calculated when I'm actually expecting 98. I know that this is due to the fact that my C compiler returns asin values in the range PI/2 to PI/2, however I don't know how to deal with it.
Incidentally, I'm not as concerned with verifying whether or not the camera can actually position itself to view the point. That will be relatively easy. I included that in the description to help indicate *why* I need to know the exact values of the pitch and yaw.
Also, the roll angle at this point is 0, but I can't guarantee that it will always be so.
Does anyone have any experience with this type of problem? If so, any help would be greatly appreciated.
Thanks
