Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

ArcTan2 Function ?

  1. Jan 15, 2008 #1
    Anyone have the Source for ArcTan2 ( x, y: Extended);
    I Can have it in most any programming language, if you can show me how it works.. then that would be great too.

    And just so you know im trying to calculate the Degrees in a line using ArcTan2;

    for example:

    Degrees := (ArcTan2(MiddleX - X, MiddleY - Y));

    MiddleX := Center of the Circle (X Axis);
    MiddleY := Center of the Circle (Y Axis);

    X := Being the Point i want to calculate (X Axis)
    Y := Being the Point i want to calculate (Y Axis)

    Thanks :D
     
    Last edited: Jan 16, 2008
  2. jcsd
  3. Jan 16, 2008 #2
    I dont know what extended means, but if you want to program the arctan(x) function, you might want to use the taylor series of the function. Its the summation of [tex]\frac{x^n}{n!}f^n(x)[/tex], where [tex]f^n(x)[/tex] is the nth derivative of the function youre finding the series of.

    If thats too much of a hassle, just look up the series online. In your case, replace x by y/x (as [tex]tan\theta=\frac{y}{x}[/tex] which gives [tex]\theta=tan^{-1}\frac{y}{x}[/tex].
     
  4. Jan 16, 2008 #3
    nvm found source :)

    thanks though...

    Code (Text):

    function ArcTan(x: Extended): Extended;
    var
      i: Integer;
    begin
      if x > 1.0 then
      begin
        Result := Pi / 2 - ArcTan(1 / x);
      end else
      begin
        for i := 0 to 200 do
        begin
          Result := Result + ((Pow((-1), i) * Pow(x, (2 * i + 1))) / (2 * i + 1))
        end;
      end;
       while Result > 360 do Result := Result - 360;
       while Result < 0 do result := result + 360;
    end;

    function ArcTan2(y, x: Extended): Extended;
    var
       A1: extended;
    begin
      A1 := Pi / 180;
     
      if (y = 0.0) and (x < 0.0) then Result := A1 * 180;
      if (y = 0.0) and (x > 0.0) then Result := 0.0;
      if (x = 0.0) and (y < 0.0) then Result := A1 * 270;
      if (x = 0.0) and (y > 0.0) then Result := A1 * 90;
      if (Result = 0.0) and (x <> 0.0) then if (Abs(y) / Abs(x) = 1.0) then
        begin
          if (y > 0.0) and (x > 0.0) then Result := A1 * 45;
          if (y > 0.0) and (x < 0.0) then Result := A1 * 135.0;
          if (y < 0.0) and (x < 0.0) then Result := A1 * 225.0;
          if (y < 0.0) and (x > 0.0) then Result := A1 * 315.0;
        end;
      if Result = 0 then
      begin
        Result := ArcTan(Abs(-y) / Abs(x));
        if (y > 0.0) and (x < 0.0) then Result := Result + A1 * 90.0;
        if (y < 0.0) and (x < 0.0) then Result := Result + A1 * 180.0;
        if (y < 0.0) and (x > 0.0) then Result := Result + A1 * 270.0;
      end;
    end;
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: ArcTan2 Function ?
  1. Fortran - Functions (Replies: 0)

  2. Functions in c (Replies: 1)

  3. Functions and arrays. (Replies: 1)

Loading...