Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find sine in Java

Tags:

java

math

Can anyone give me a quick tip?

For example....how would I find the sine of 90 degrees?

like image 786
relyt Avatar asked Feb 27 '10 23:02

relyt


People also ask

How do you calculate sin in Java?

sin() returns the trigonometry sine of an angle in between 0.0 and pi. If the argument is NaN or infinity, then the result is NaN. If the argument is zero, then the result is a zero with the same sign as the argument.

How do you do sin 2 in Java?

sin^2(value) in maths is equal to Java Math. sin(value) * Math. sin(value), which can be simplified by making Math. sin(value) a variable and use it instead of computing the sin two times.

Does Math sin use radians in Java?

sin() method does. Yes, you convert your degrees value into a radians value first.

How do you find cos in Java?

cos(double a) returns the trigonometric cosine of an angle. If the argument is NaN or an infinity, then the result is NaN. The computed result must be within 1 ulp of the exact result.


2 Answers

The sin function in java.lang.Math expects a parameter expressed in radians.

I think you should use Math.sin(Math.toRadians(90))

like image 82
wcm Avatar answered Nov 13 '22 20:11

wcm


You could use the Math.sin function where the argument is given in radians. Example:

double result = Math.sin(Math.PI / 2.0);
like image 35
Darin Dimitrov Avatar answered Nov 13 '22 19:11

Darin Dimitrov