Archived

This topic is now archived and is closed to further replies.

Bruno

finding the angle

Recommended Posts

Bruno    155
Hello I have my camera located at (x,y,z), and looking at the direction (x1,y1,z1). If i have a model at (x2,y2,z2), how do i find the angle between the model(x2,y2,z2) and my camera(x,y,z) ??? thanks , Bruno

Share this post


Link to post
Share on other sites
Cedric    158
The short answer is to use the dot product.

But please, use the search feature to find "angle between two vectors". It will be more detailed.

Thank you,

Cédric

Share this post


Link to post
Share on other sites
capn_midnight    1707
your three points define a triangle. Use the law of cosines:

a2 + b2 - 2ab cosA = c2

where A is the angle between sides a and b. so, in your case, you want to know a, so you rewrite the equation:

(a2 + b2 - c2)/2ab = cosA
arccos((a2 + b2 - c2)/2ab) = A

a2=dx12 + dy12 + dz12

b2=dx22 + dy22 + dz22

dx1 = x1 - x
dy1 = y1 - y
dz1 = z1 - z
dx2 = x2 - x
dy2 = y2 - y
dz2 = z2 - z

check the time on my post. If it is more than 10 minutes old, then I don't have any corrections pending.


Do you use your powers for good or for awesome?
|My site | Association of Computing Machinery

[edited by - capn_midnight on September 2, 2003 4:05:21 PM]

[edited by - capn_midnight on September 2, 2003 4:09:02 PM]

Share this post


Link to post
Share on other sites