Results 1 to 7 of 7

Thread: Vectors to angles?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    USA all the way!
    Posts
    82

    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?

  2. #2
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    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:
    1. magnitude = sqr((X^2)+(Y^2))
    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.


  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    USA all the way!
    Posts
    82
    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?

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  5. #5
    Member SapphireGreen's Avatar
    Join Date
    Sep 2001
    Location
    I do not actually exist
    Posts
    45
    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.

  6. #6
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    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:
    1. Public Function Arctan2(y As Double, x As Double) As Double
    2.  
    3.     If x = 0 Then
    4.         If y > 0 Then
    5.             Arctan2 = HALFPI
    6.         Else
    7.             Arctan2 = -HALFPI
    8.         End If
    9.     ElseIf x > 0 Then
    10.         Arctan2 = Atn(y / x)
    11.     Else
    12.         If y < 0 Then
    13.             Arctan2 = Atn(y / x) - PI
    14.         Else
    15.             Arctan2 = Atn(y / x) + PI
    16.         End If
    17.     End If
    18.  
    19. End Function

    SapphireGreen, what's the location of the camera? If you only have a lookat point, then you can't calculate anything.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    USA all the way!
    Posts
    82
    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
  •  



Click Here to Expand Forum to Full Width