[JAVA] Math ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ์ผ๊ฐํจ์, ์ญ์ผ๊ฐํจ์ ์ฌ์ฉ๋ฒ
์ก์ญ๋ถ๋ฒ(๋ผ๋์) | 0(0) | 30(∏/6) | 45(∏/4) | 60(∏/3) | 90(∏/2) |
sin | 0 | 1/2 | √2/2 | √3/2 | 1 |
cos | 1 | √3/2 | √2/2 | 1/2 | 0 |
tan | 0 | √3/3 | 1 | √3 | ∞ |
โป 360ห = 2∏
1. Math.toRadians(double angdeg) : ์ก์ญ๋ถ๋ฒ → ๋ผ๋์, doubleํ ๋ฐํ
doubleํ์ผ๋ก์ธํด ์ค์ฐจ๊ฐ ์์.
Math.toRadians(0); // 0.0
Math.toRadians(30); // 0.5235987755982988 (∏/6 ์ ๊ณ์ฐ)
Math.toRadians(45); // 0.7853981633974483 (∏/4 ์ ๊ณ์ฐ)
Math.toRadians(60); // 1.0471975511965976 (∏/3 ์ ๊ณ์ฐ)
Math.toRadians(90); // 1.5707963267948966 (∏/2 ์ ๊ณ์ฐ)
2. Math.toDegrees(double angrad) : ๋ผ๋์ → ์ก์ญ๋ถ๋ฒ, doubleํ ๋ฐํ
doubleํ์ผ๋ก์ธํด ์ค์ฐจ๊ฐ ์์.
Math.toDegrees(Math.PI/6); // 29.999999999999996
Math.toDegrees(Math.PI/4); // 45.0
Math.toDegrees(Math.PI/3); // 59.99999999999999
Math.toDegrees(Math.PI/2); // 90.0
3. Math.sin(double a) : sin ๊ฐ, ํ๋ผ๋ฏธํฐ๋ก ๋ผ๋์ ๊ฐ์ ๋๊ฒจ์ค์ผ ํจ
Math.sin(0); // 0.0
Math.sin(Math.PI/6); // 0.49999999999999994
Math.sin(Math.PI/4); // 0.7071067811865475
Math.sin(Math.PI/3); // 0.8660254037844386
Math.sin(Math.PI/2); // 1.0
4. Math.cos(double a) : cos ๊ฐ, ํ๋ผ๋ฏธํฐ๋ก ๋ผ๋์ ๊ฐ์ ๋๊ฒจ์ค์ผ ํจ
Math.cos(0); // 1.0
Math.cos(Math.PI/6); // 0.8660254037844387
Math.cos(Math.PI/4); // 0.7071067811865475
Math.cos(Math.PI/3); // 0.5000000000000001
Math.cos(Math.PI/2); // 6.123233995736766E-17
Math.cos(Math.PI/2) ์ ๊ฐ์ด 0์ด ์๋ 6.123233995736766E-17 ๊ฐ์ด ๋์๋ค๊ณ ํด์ ์ฐพ์๋ดค๋๋ฐ
6.123233995736766E-17 ์ 6.12323399573676 X e^(-17) ์ด๋ผ๊ณ ํ๋ค. ๋ฐ๋ผ์ 0์ ๊ฐ๊น์ด ์๋ผ๊ณ ๋ณผ ์ ์๋ค.
double ํ ์ค์ฐจ๋๋ฌธ์ ๊ทธ๋ฐ๊ฑฐ ๊ฐ์๋ฐ... 0์ด๋ผ๊ณ ์๊ฐํ๋ฉด ๋๋ค....
๋ ์์ธํ ๊ฑด ์๋์ ์ฌ์ดํธ์์ ํ์ธํ ์ ์๋ค.
Why does Math.cos(90 * Math.PI/180) yield 6.123031769111... and not zero?
I convert degrees to radians (degrees * Math.PI/180) but why does the following: Math.cos(90 * Math.PI/180) yield 6.123031769111... and not zero? I'm trying to perform 2D rotations uses matrixes...
stackoverflow.com
5. Math.tan(double a) : tan ๊ฐ, ํ๋ผ๋ฏธํฐ๋ก ๋ผ๋์ ๊ฐ์ ๋๊ฒจ์ค์ผ ํจ
Math.tan(0); // 0.0
Math.tan(Math.PI/6); // 0.5773502691896257
Math.tan(Math.PI/4); // 0.9999999999999999
Math.tan(Math.PI/3); // 1.7320508075688767
Math.tan(Math.PI/2); // 1.633123935319537E16
Math.tan(Math.PI/2) ์ ๊ฒฐ๊ณผ๊ฐ๋ ๋ณด๋ฉด 1.633123935319537 X e^(16) ์ด๋ฏ๋ก ๋งค์ฐ ํฐ ์๋ผ๊ณ ์๊ฐํ๋ฉด ๋๋ค...
์ญ์ผ๊ฐํจ์
- sin(30ห) = 1/2 โ 30ห = sin^(-1) (1/2) โ 30ห = arcsin(1/2)
- cos(30ห) = √3/2 โ 30ห = cos^(-1) (√3/2) โ 30ห = arccos(√3/2)
- tan(30ห) = √3/3 โ 30ห = tan^(-1) (√3/3) โ 30ห = arctan(√3/3)
๋ ๋ณ์ ์ด์ฉํด์ ๊ฐ๋๋ฅผ ๊ตฌํ ๋ ์ฐ๋ ๋ฏ...?
6. Math.asin(double a) : arcsin ๊ฐ, ํ๋ผ๋ฏธํฐ๋ก ๋น๋ณ / ๋์ด
Math.asin(0); // 0.0 (0๋)
Math.asin(Math.sqrt(1)/2); // 0.5235987755982989 (30๋)
Math.asin(Math.sqrt(2)/2); // 0.7853981633974484 (45๋)
Math.asin(Math.sqrt(3)/2); // 1.0471975511965976 (60๋)
Math.asin(Math.sqrt(4)/2); // 1.5707963267948966 (90๋)
7. Math.acos(double a) : arccos ๊ฐ, ํ๋ผ๋ฏธํฐ๋ก ๋น๋ณ / ๋ฐ๋ณ
Math.acos(0); // 1.5707963267948966 (90๋)
Math.acos(Math.sqrt(1)/2); // 1.0471975511965976 (60๋)
Math.acos(Math.sqrt(2)/2); // 0.7853981633974484 (45๋)
Math.acos(Math.sqrt(3)/2); // 0.5235987755982989 (30๋)
Math.acos(Math.sqrt(4)/2); // 0.0 (0๋)
8. Math.atan(double a) : arctan ๊ฐ, ํ๋ผ๋ฏธํฐ๋ก ๋์ด / ๋ฐ๋ณ
Math.atan(0); // 0.0 (0๋)
Math.atan(Math.sqrt(3)/3); // 0.5235987755982988 (30๋)
Math.atan(Math.sqrt(9)/3); // 0.7853981633974483 (45๋)
Math.atan(Math.sqrt(27)/3); // 1.0471975511965979 (60๋)
Math.atan(Long.MAX_VALUE); // 1.5707963267948966 (90๋)
9. Math.atan2(double y, double x) : arctan ๊ฐ, ํ๋ผ๋ฏธํฐ๋ก ์ขํ๋ฅผ ์ ๋ฌ(์์ ๊ณผ ํ๋ผ๋ฏธํฐ์ ์ขํ ๋ ์ ์ ๊ธฐ์ค์ผ๋ก arctan ๊ฐ์ ๋ฐํ)
// y๊ฐ์ด ์ฒซ๋ฒ์งธ ํ๋ผ๋ฏธํฐ, x๊ฐ์ด ๋๋ฒ์งธ ํ๋ผ๋ฏธํฐ!!!
Math.atan2(Math.sqrt(0), 3); // 0.0 (0๋)
Math.atan2(Math.sqrt(3), 3); // 0.5235987755982988 (30๋)
Math.atan2(Math.sqrt(9), 3); // 0.7853981633974483 (45๋)
Math.atan2(Math.sqrt(27), 3); // 1.0471975511965979 (60๋)
Math.atan2(Long.MAX_VALUE, 3); // 1.5707963267948966 (90๋)
'JAVA' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JAVA] PrintWriter์ write()์ print() ์ฐจ์ด์ (0) | 2022.03.23 |
---|---|
[JAVA] ์๋ฐ ๋ฐฐ์ด ์ ๋ ฌ(Comparable, Comparator) (0) | 2022.01.27 |
[JAVA] ์๋ฐ LinkedList (0) | 2022.01.26 |
[JAVA] ์๋ฐ ArrayList (0) | 2022.01.26 |