Java如何使用三角计算方法?
本示例演示如何使用java.lang.Math该类的三角方法。你可以看到使用方法,如Math.sin(),Math.cos(),Math.tan(),等。
package org.nhooo.example.math; public class TrigonometricExample { public static void main(String[] args) { double radians = 1.0d; double sine = Math.sin(radians); double cosine = Math.cos(radians); double tan = Math.tan(radians); double asine = Math.asin(sine); double acosine = Math.acos(cosine); double atan = Math.atan(tan); System.out.println("Sine of " + radians + " = " + sine); System.out.println("Cosine of " + radians + " = " + cosine); System.out.println("Tangent of " + radians + " = " + tan); System.out.println("Arcsine of " + sine + " = " + asine); System.out.println("Arccosine of " + cosine + " = " + acosine); System.out.println("Arctangent of " + tan + " = " + atan); } }
该程序的输出为:
Sine of 1.0 = 0.8414709848078965 Cosine of 1.0 = 0.5403023058681398 Tangent of 1.0 = 1.5574077246549023 Arcsine of 0.8414709848078965 = 1.0 Arccosine of 0.5403023058681398 = 1.0 Arctangent of 1.5574077246549023 = 1.0