Angle between 2 objects eg.

jacko13 101 Nov 19, 2009 at 16:42

Hi, I have question, how can I calculate current angle between 2 objects. Eg. 1st is camera and 2nd is Cube. I need this for check, is angle between this objects are smaller or bigger than 50 degrees etc.

2 Replies

Please log in or register to post a reply.

Mihail121 102 Nov 19, 2009 at 16:57

Oh my God, not again, pick some books for Christ’ sake and use your brain. Camera is ok, but how can a cube has a property like orientation and direction?? You need two vectors to do this. The 1st is the direction of the camera and the 2nd should be something unknown to be and probably to you. Then you use both vectors as arguments to an operation known as dot product or, alternatively, scalar product.

SyntaxError 101 Nov 19, 2009 at 19:44

I’m assuming you mean the angel between the vector along which the camera is pointing and the vector from the camera to some point in or on the cube. If you have a vector of length one (a unit vector) describing the direction your camera points and also the point where your camera is located, you can subtract the camera point from the cube point to give you a second vector. Then you normalize that vector (divide it’s X,Y and Z components by it’s length) to make it a unit vector. Now you take the acos of the dot product of you your two unit vectors and you have your answer.