|
-
Apr 7th, 2002, 10:31 AM
#1
Thread Starter
Lively Member
Vectors to angles?
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?
Often talked of, never seen,
Ever coming, never been,
Daily looked for, never here,
Still approaching, coming near,
Thousands for its visit wait,
But alas for their fate,
Tho' they expect me to appear,
They will never find me here.
What's this about?
-
Apr 7th, 2002, 04:08 PM
#2
Not NoteMe
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)
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Apr 7th, 2002, 05:59 PM
#3
Thread Starter
Lively Member
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.)?
Often talked of, never seen,
Ever coming, never been,
Daily looked for, never here,
Still approaching, coming near,
Thousands for its visit wait,
But alas for their fate,
Tho' they expect me to appear,
They will never find me here.
What's this about?
-
Apr 7th, 2002, 08:14 PM
#4
transcendental analytic
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:
Code:
a
|\
| \
|x \
|_y_\
3. 270-a*180/pi
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Apr 8th, 2002, 03:29 AM
#5
Member
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)?
On Error Give Up
Mind over matter. Then if it doesn't matter, you lose your mind.
-
Apr 8th, 2002, 11:58 AM
#6
Fanatic Member
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.
-
Apr 10th, 2002, 03:35 PM
#7
Thread Starter
Lively Member
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.)
Often talked of, never seen,
Ever coming, never been,
Daily looked for, never here,
Still approaching, coming near,
Thousands for its visit wait,
But alas for their fate,
Tho' they expect me to appear,
They will never find me here.
What's this about?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|