Angle between kx_camera and 3D point

Hey all,

I’ve been looking through the threads a lot but have not come across this question.

I’m trying to determine the angle between a kx_camera and a point in 3-space. I know I can use the getVectTo to get a vector to the point and I know there’s a .orientation (matrix). I have a feeling that that’s enough to derive the answer, I just don’t know how. Any help would be great.

Thanks,

Sterling

Keep in mind: Points have no angle

I guess you mean: the angle between the camera’s forward vector and the vector from camera to the desired poisition.

As angles are usually not really useful, may I ask why you think you need it?

Sure. I’m building a robot simulation in MORSE which uses blender. But atypically, I have no interest in AI vision, so I my plan was just to use direct access to bge to give my robot perfect vision - however, I still need the vision system to have a perspective. My plan is to use a kx_camera so that I can exploit the (box, sphere, point --InsideFrustum()) to determine what is in front of the camera. This I’ve done. I also wrote a quick script to find out the exact points that can be seen within the frustum, etc. While I can determine that an object is within the frustum, I don’t know where within that space anything is… i.e. is it directly in front of the camera, is it to the front-left, front-right, etc. I know I can get the vector to the vertex but I want it to be relative to the rotation of the camera. So, yes, I want the angle from the camera’s forward vector to the vector to the desired position. The task is to walk between two walls (and rotate shoulders if needed, which is controlled from a cognitive simulation tool).

I know how to make the calculation if the robot is orthogonal to the wall (acos) but I realized write after I wrote that, that it wouldn’t work if the robot was not approaching the walls orthogonally. I do assume there is a way to use the orientation matrix of the camera and the vector to the vertex to find the angle between the two…

And of course, if there’s a much easier way, I’m all ears :slight_smile:

Thanks!

I am reviewing my geometry. Is the third row of the orientation matrix the normal of the rotation?

I think this is solved. (do I mark it as solved?)

I haven’t verified it in code yet but I believe the first column of the rotation matrix is a vector parallel to the rotation. If you then take a vector from the centre of the camera, to the point in question, you can just get the angle between the two vectors. It looks to be about right.