Find Source & Learn ArcTan2 for Degrees Calculation

  • Thread starter Thread starter Sky Scripter
  • Start date Start date
  • Tags Tags
    Function
Sky Scripter
Messages
5
Reaction score
0
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 I am 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:
on Phys.org
I don't 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 that's 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].
 
nvm found source :)

thanks though...

Code:
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;
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
Replies
3
Views
2K
Replies
3
Views
1K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
2
Views
2K