Results 1 to 3 of 3

Thread: Angles

  1. #1

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Angles

    My brain is giving up completely and I have the flu.

    Given a vector [5,-3], how do you work out the compass bearing?
    Last edited by wossname; Feb 8th, 2005 at 08:35 AM.
    I don't live here any more.

  2. #2
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    703

    Re: Angles

    Normalise it and dot it with the unit vector in the N dir: (0,1)

    (5,-3) -> magnitude = sqrt(5^2 + 3^2) = root 34

    normalised vector = ( 5/sqrt(34), -3/sqrt(34) )

    Dot product:

    A dot B = mag(A)*mag(B)*cos(theta)

    If you want a bearing then you can subtract from 360 as appropriate.
    an ending

  3. #3
    Fanatic Member sql_lall's Avatar
    Join Date
    Jul 2002
    Location
    Up Above (i.e. AUS)
    Posts
    571

    Re: Angles

    Alternatively, you know:
    (5, -3) = r*(cos(theta), sin(theta)) where theta = 90 - bearing
    - think 5 - 3i = r cis(theta)
    also, r = length = sqrt(34)

    so, really:
    (5, -3) = (r sin(bearing), r cos(bearing))

    => tan(bearing) = 5 / -3
    now, there are two options, one of which is obviously true, one of which is 180 degrees out.


    (BTW, if it's in C++, you can use bearing = atan2(5, -3))
    sql_lall

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