Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Math.cos() & Math.sin()? [duplicate]

Tags:

java

math

I'm using Math.cos and Math.sin but it returns me unexpected results like these:

 Angle   Sin      Cos
 354     0.8414  -0.5403
 352     0.1411   0.98998
 350    -0.958   -0.2836

Why I get these results?

like image 647
joanlopez Avatar asked Dec 19 '12 11:12

joanlopez


People also ask

What does math cos () do in Python?

In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math. cos() function returns the cosine of value passed as argument. The value passed in this function should be in radians.

What is the use of math cos?

The Math. cos() method is used to return the cosine of a number. The Math. cos() method returns a numeric value between -1 and 1, which represents the cosine of the angle given in radians.

Does math cos return radians or degrees?

cos() returns the cosine of a number (radians) that is sent as a parameter.

What is the formula for cos?

What is the cosine formula? The cosine formula to find the side of the triangle is given by: c = √[a2 + b2 – 2ab cos C] Where a,b and c are the sides of the triangle.


2 Answers

Are you trying to use degrees? Keep in mind that sin and cos are expecting radians.

Math.cos(Math.toRadians(354))
like image 63
Pubby Avatar answered Sep 23 '22 21:09

Pubby


Math.cos and Math.sin take angles in radians, not degrees. So you can use:

double angleInDegree = 354;
double angleInRadian = Math.toRadians(angleInDegree);
double cos = Math.cos(angleInRadian); // cos = 0.9945218953682733
like image 22
assylias Avatar answered Sep 23 '22 21:09

assylias