was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

45 Visitors Online


 
...den Arctan im Bereich [-PI/2;3/2*PI] bestimmen?
Autor: Uffe Jakobsen
[ Tip ausdrucken ]  

Tip Bewertung (12):  
     



{
A simple but usefull tiny tip.
This version of Arctan is valid throughout the
interval [-PI/2;3/2*PI] unlike normally only ]-PI/2;PI/2[.
It is of use when you need to convert a given vector from rectangular to
polar format. It is quite handy when you do complex numbers.

Furthermore it allows finding angles of vertical lines or purely imaginery complex numbers.
A similar function exists in the standard libraries of MOSCOW-ML and C/C++, but not in DELPHI math.
}

function ArcTan2(x, y: Double): Double;
var
  
retur: Double;
begin
  
Retur := 0.0;
  if ABS(x) < 0.000000001 then //Close to zero! We declare it to be zero!
  
begin //The small margin gives a slight error, but improves reliability.
    
if y > 0 then
    begin
      
Retur := PI / 2; //90 degrees
    
end
    else
    begin
      
Retur := PI / (-2); //-90 degrees
    
end;
  end
  else
  begin
    if 
x > 0 then // 1. or 4. quadrant
    
begin
      
Retur := ArcTan(Y / X); // Easy stuff. Normal ArcTan is valid for 1. and 4.
    
end
    else 
// 2. or 3. quadrant
    
begin
      
Retur := PI - ArcTan(-Y / X);
    end;
  end;
  ArcTan2 := Retur;
end;


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners