javascripttransformdegrees

Converting transform radian to degree value is not showing properly for few values using javascript


  1. Radian to degree: var Degrees = Radian * (180 / Math.PI)

  2. Degree to transform var bval=Math.sin(45*Math.PI / 180);

  3. Transform to angle var angle = Math.round(Math.asin(bval) * (180/Math.PI));

  4. Degree to radian: var Radians = Degree * Math.PI/180

The above steps tried with the below code with values "-3.17934" & "-0.9998"

  1. "-3.17934" --> This value properly converted not closed to First Radian & Last radian
  2. "-0.9998" --> This value properly converted & closed to First Radian & Last radian
`<script>
console.log("--------------------------------");
//var rad2="-3.17934";//-3.17934
var rad2="-0.9998";//-0.9998
console.log("First radian:  "+rad2);
var rad2angle = rad2 * (180/Math.PI);
console.log("2 rad2angle: "+rad2angle);

var tt = Math.sin(rad2angle*Math.PI / 180);
console.log("3 To Transform: "+tt);

var t2angle = Math.round(Math.asin(tt) * (180/Math.PI));
console.log("2 t2angle: "+t2angle);

var angle2radian = t2angle * Math.PI/180;
console.log("Last radian:  "+angle2radian);
</script>`

Thanks in Advance.

I tried with above code given in detail area.


Solution

  • I have modified the code & i got the proper output. Thanks everyone.

    <script>
    console.log("--------------------------------");
    
    var rad2="-0.9998";
    console.log("1- Radian Value:  "+rad2);
    
    var rad2angle = rad2 * (180/Math.PI);
    console.log("2- Radian to Angle: "+rad2angle);
    
    var cos=Math.cos(rad2angle*Math.PI / 180);
    var sin=Math.sin(rad2angle*Math.PI / 180);
    var catrans = [];
    const trans = [cos, sin, -sin, cos, 0, 0];
    console.log("3- Form Transform: "+trans.toString());
    var tt= Math.atan2(sin,cos); 
    var angle2radian = tt * 180/Math.PI;
    
    console.log("2- Transform to Angle:  "+angle2radian);
    console.log("1- Angle to radian: "+tt);
    </script>