Find Source & Learn ArcTan2 for Degrees Calculation

  • Thread starter Thread starter Sky Scripter
  • Start date Start date
  • Tags Tags
    Function
AI Thread Summary
The discussion focuses on implementing the ArcTan2 function in programming to calculate the angle in degrees between a point and the center of a circle. The user seeks a source code example and clarification on the term "Extended." The ArcTan2 function is defined using a combination of conditional checks for quadrants and the ArcTan function, which is approximated using a Taylor series. The provided code includes detailed logic for handling various cases based on the signs of the x and y coordinates, ensuring accurate angle calculations across all quadrants. The conversation highlights the importance of understanding the mathematical basis behind the function and offers a practical implementation in code.
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:
Technology news 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 \frac{x^n}{n!}f^n(x), where f^n(x) 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 tan\theta=\frac{y}{x} which gives \theta=tan^{-1}\frac{y}{x}.
 
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;
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...
Back
Top