C ++ atan2 () - C ++ standaardbibliotheek

De functie atan2 () in C ++ geeft de inverse tangens van een coördinaat in radialen terug.

Deze functie is gedefinieerd in het header-bestand.

(Wiskunde) tan -1 (y / x) = atan2 (y, x) (in C ++ programmeren)

atan2 () prototype (vanaf C ++ 11-standaard)

dubbel atan2 (dubbel y, dubbel x); float atan2 (float y, float x); lang dubbel atan2 (lang dubbel y, lang dubbel x); dubbele atan2 (Type1 y, Type2 x); // Voor combinaties van rekenkundige typen.

atan2 () Parameters

De functie atan2 () heeft twee argumenten: x-coördinaat en y-coördinaat.

  • x - deze waarde vertegenwoordigt de proportie van de x-coördinaat.
  • y - deze waarde vertegenwoordigt de proportie van de y-coördinaat.

atan2 () Retourwaarde

De functie atan2 () retourneert de waarde in het bereik van (-π, π) . Als x en y beide nul zijn, retourneert de functie atan2 () 0.

Voorbeeld 1: Hoe werkt atan2 () met hetzelfde type x en y?

 #include #include using namespace std; int main() ( double x = 10.0, y = -10.0, result; result = atan2(y, x); cout << "atan2(y/x) = " << result << " radians" << endl; cout << "atan2(y/x) = " << result*180/3.141592 << " degrees" << endl; return 0; )

Wanneer u het programma uitvoert, is de uitvoer:

 atan2 (y / x) = -0.785398 radialen atan2 (y / x) = -45 graden

Voorbeeld 2: Hoe werkt atan2 () met verschillende typen x en y?

 #include #include #define PI 3.141592654 using namespace std; int main() ( double result; float x = -31.6; int y = 3; result = atan2(y, x); cout << "atan2(y/x) = " << result << " radians" << endl; // Display result in degrees cout << "atan2(y/x) = " << result*180/PI << " degrees"; return 0; ) 

Wanneer u het programma uitvoert, is de uitvoer:

 atan2 (y / x) = 3.04694 radialen atan2 (y / x) = 174.577 graden

Interessante artikelen...