Java中的三角函数
java.lang.Math 类包含三角函数方法,如 cos()、sin()、tan()、tanh()、cosh()、atan() 等。
让我们来了解一下 Java 中的一些三角函数 −
static double asin(double a)
java.lang.Math.asin(double a) 返回角度的反正弦值,在 -pi/2 到 pi/2 的范围内。
现在让我们看一个示例 −
示例
import java.util.*;
public class Main {
public static void main(String args[]) {
// get a variable x which is equal to PI/2
double x = Math.PI / 2;
// convert x to radians
x = Math.toRadians(x);
// get the arc sine of x
System.out.println("Math.asin(" + x + ")=" + Math.asin(x));
}
}输出
Math.asin(0.027415567780803774)=0.02741900326072046
static double atan(double a)
atan() 方法返回角度的反正切值,在 -pi/2 到 pi/2 的范围内。
现在让我们看一个示例,在 Java 中实现 atan() 方法 −
示例
import java.util.*;
public class Main {
public static void main(String args[]) {
// get a variable x which is equal to PI/2
double x = Math.PI / 2;
// convert x to radians
x = Math.toRadians(x);
// get the arc tangent of x
System.out.println("Math.atan(" + x + ")" + Math.atan(x));
}
}输出
Math.atan(0.027415567780803774)0.0274087022410345
static double cosh(double x)
java.lang.Math.cosh(double a) 返回双精度的双曲余弦值。
现在让我们看一个示例,在 Java 中实现 cosh() 方法 −
示例
import java.util.*;
public class Main {
public static void main(String args[]) {
// get two double numbers
double x = 45.0;
double y = 180.0;
// convert them to radians
x = Math.toRadians(x);
y = Math.toRadians(y);
// print their hyperbolic cosine
System.out.println("Math.cosh(" + x + ")=" + Math.cosh(x));
System.out.println("Math.cosh(" + y + ")=" + Math.cosh(y));
}
}输出
Math.cosh(0.7853981633974483)=1.3246090892520057 Math.cosh(3.141592653589793)=11.591953275521519
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP