English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
تقوم دالة atan2() في C++ بإرجاع زاوية معكوسة للنقطة بالراديان.
هذا الدالة في<cmath>محدد في ملف الرأس.
tan-1(y/x) = atan2(y, x)
double atan2(double y, double x); float atan2(float y, float x); long double atan2(long double y, long double x); double atan2(Type1 y, Type2 x); // تستخدم للتركيبات من أنواع حسابية.
يملك دالة atan2() إثنين من المعلمات: x و y
x -هذا القيمة تعبر عن النسبة لـ x
y -هذا القيمة تعبر عن النسبة لـ y
تتكون العودة من دالة atan2()[-π، π]القيم في النطاق. إذا كان x و y كلاهما صفرًا، فإن دالة atan2() ستعود 0.
#include <iostream> #include <cmath> 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 << " درجة" << endl; return 0; }
عند تشغيل هذا البرنامج، الناتج سيكون:
atan2(y/x) = -0.785398 راديان atan2(y/x) = -45 درجة
#include <iostream> #include <cmath> #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; // عرض النتيجة بالدرجات cout << "atan2(y/x) = " << result*180/PI << " degrees"; return 0; }
عند تشغيل هذا البرنامج، الناتج سيكون:
atan2(y/x) = 3.04694 راديان atan2(y/x) = 174.577 درجات