Java Math atan2 () metode pārveido norādītās taisnstūra koordinātas (x, y) polārajās koordinātās (r, θ) un atgriež leņķi teta (θ).
Metodes sintakse atan2()
ir šāda:
Math.atan2(double y, double x)
Šeit atan2()
ir statiska metode. Tādējādi mēs piekļūstam metodei, izmantojot klases nosaukumu Math
,.
atan2 () parametri
atan2()
Metode ņem divus parametrus.
- x / y - taisnstūra koordinātas x un y
Piezīme : koordinātas x un y apzīmē punktu divdimensiju plaknē.
atan2 () atgriešanās vērtības
- atgriež leņķi θ, pārveidojot koordinātas (x, y) par koordinātām (r, θ)
Piemērs: Java Math.atan2 ()
class Main ( public static void main(String() args) ( // two coordinates x and y double x = 3.7; double y = 6.45; // get angle θ double theta = Math.atan2(y, x); System.out.println(theta); // 1.0499821573815171 // convert into the degree System.out.println(Math.toDegrees(theta)); // 60.15954618200191 ) )
Šeit atan2()
metode pārveido koordinātas (x, y) par koordinātām (r, θ) un atgriež leņķi teta (θ).
Mēs izmantojām metodi Math.toDegrees (), lai leņķi θ
pārvērstu pakāpē.