Skip to main content
gamedev.net
🔒 Locked

finding the angle

Started by Bruno 1 reply 500+ views
Original Post
Bruno
Bruno
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
Cedric
Cedric
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
capn_midnight
capn_midnight
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]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.