Convert radians to degrees


I am doing a calculation to obtain a value in degrees, but I have found that the result of an operation in JavaScript , where the types of trigonometric operations intervene, throws these values in radians.


23.45 * sin(360 * ((284 + dn)/365))

Then I perform in JavaScript as follows:

var miVariable = 23.45 * Math.sin(360 * ((284 + 196)/365));

The value thrown is 19.15 , of course, rounding off the final value.

The problem is that JavaScript gives the result in radians, and I want it in degrees. I searched, and the solution they give is, multiply the result in radians in the following way:

miVariable * (180/Math.PI);

... but the value thrown is 1097.2141776755263

Similarly, if I multiply the result but only the calculation of the sine operation, it falls within a possible range of -360 and 360 .

var valorSeno = Math.sin(360 * ((284 + 196)/365));
var valorFinal = valorSeno * (180/Math.PI);

Similarly, here I still do not multiply by the value 23.45 , since it throws, the same value at the end.

The final value I need is 21.51

asked by Pedro Miguel Pimienta Morales 03.05.2018 в 02:13

3 answers


You have to play around with the conventions to keep all the equivalences.

You well know that the function of Math.sin (x) receives its parameters as radians. The result is still in radians .

Hence the algebra of the school applies to solve the breast and give a final conversion to obtain the degrees.

Math.grados = function(radianes) {
  return radianes * 180 / Math.PI;

Math.radianes = function(grados) {
  return grados * Math.PI / 180;

let antesSeno = Math.radianes(360 * ((284 + 196)/365)),
  miVariable = 23.45 * Math.sin(antesSeno),
  miGrados = Math.grados(miVariable);
answered by 03.05.2018 / 02:43

The result can be obtained in degrees, without converting radians to degrees. Instead, I decided to make a small change in the mathematical formula.

The original formula is this:

23.45 * sin(360 * ((284 + dn)/365))

I just changed the 360 to twice the pi ( 2*Math.PI ). Apparently, 180º is the equivalence of pi.

I have programmed the function so that it adapts to the number of days that the year has, that is, whether it is a leap year or not.

var dn = 196
var declinación = (dn,días)=>23.45*Math.sin(2*Math.PI*(284+dn)/días)

function formatear(i,días)
  var dec = declinación(i,días)
  var signo = 2*+(dec>=0)-1
  var dec_abs = Math.abs(dec)
  var grados = Math.floor(dec_abs)
  var minutos = Math.floor((dec_abs-grados)*60)
  var segundos = Math.floor(((dec_abs-grados)*60-minutos)*60)
  return i+" "+días+"\t"+grados*signo+"º\t"+minutos+"'\t"+segundos+"''\t"+dec+"\n"


var salida=""
for(var i=1;i<=366;i++)
answered by 04.05.2018 в 19:00

I think the formula to convert this is wrong and it should be like this:

const dregreesToRadian = deg => deg * Math.PI / 180;
answered by 03.05.2018 в 02:45