I need to know if there is a formula that lets me take a vector, say 12,8 and convert it to degrees.
PS- does anyone know of a DirectX tutorial that starts from the beginning, for someone who has never programmed in DX before?
Printable View
I need to know if there is a formula that lets me take a vector, say 12,8 and convert it to degrees.
PS- does anyone know of a DirectX tutorial that starts from the beginning, for someone who has never programmed in DX before?
I assume that 12 is along the x axis, and 8 is along the y axis.
If it is, then the angle would be from the xaxis, anti-clockwise, to the vector direction.
VB Code:
magnitude = sqr((X^2)+(Y^2)) angle = atn(Y/X)
i kinda understand, but could you clarify:
1 What is the magnitude formula for?
2 What does atn do?
3 Is there any way to measure the angle from the y-axis, clockwise (vector 0,10=0 degrees; 10,0=90 degrees, etc.)?
1. magnitude is the length of the vector
2. atn is short for arcus tangent, which is the name of a function to retrieve the angle a in radians in this triangle of any x and y:
3. 270-a*180/piCode:a
|\
| \
|x \
|_y_\
Isn't that just inverse TAN? Anyway.
If I have a D3D camera looking at pont 0,0,0 (origin), and I want to move it 15 degrees to the right on the X-axis (which is positive), how do I calculate what point it's looking at now?
Likewise, how do I do the reverse (make it look at point 5,0,0 and then calculate the degree of rotation)?
Atn is the inverse of tan, that's right.
Atn is fine, if you don't need the direction of the angle, since Atn will always give a result between -1/2 pi and +1/2 pi.
Use this formula if you want to take the direction of the vector into account:
VB Code:
Public Function Arctan2(y As Double, x As Double) As Double If x = 0 Then If y > 0 Then Arctan2 = HALFPI Else Arctan2 = -HALFPI End If ElseIf x > 0 Then Arctan2 = Atn(y / x) Else If y < 0 Then Arctan2 = Atn(y / x) - PI Else Arctan2 = Atn(y / x) + PI End If End If End Function
SapphireGreen, what's the location of the camera? If you only have a lookat point, then you can't calculate anything.
Thnx. It sorta works, but I still sometimes get negative angles. I need something that will go 0-359 degrees, starting at 12 o' clock and going clockwise.
(I'm not to good at this kind of math, or else I'd probably be able to fix this myself.)