Thread: arccos problem

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    40

    arccos problem

    I've been digging on this site and through google, but I can't find an arccos function anywhere; all I find are discussions about it and about dot products which I don't understand, it's all theory behind arccos which I would like to understand and would use to make the function if I could.

    All I want to do is find the angle of one object relative to another object's location and heading, and to do so I'm trying to find the difference between the reference's heading and the angle made by the location of the reference and target.

    Does anyone know where I can find either a premade arccos function or a simple explanation of it that would allow me to program my own for use in my GetAngle function?

    Here's my simple function I'm using it in.
    Code:
    float GetAngle(object targ, object ref)
    {                                 
      float x = targ.loc.x - ref.loc.x;
      float y = targ.loc.y - ref.loc.y;
      float r = sqrt(x*x + y*y);
      float theta = arccos((y*y + r*r - x*x)/(2*y*r));
      return theta - ref.heading;
    }
    Thanks in advance for any explanation you might be able to provide.

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    40
    That math.h it mentioned did the trick. Thanks again.

    I feel my headache going away already.

    (edit)
    It's been a while, but didn't there used to be a way to mark my thread as resolved? The thread tools only seems to have printing, emailing, subscribing and adding a poll to the thread now. How do I tag it now?
    (/edit)
    Last edited by Loduwijk; 07-26-2006 at 06:38 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM