Robert Linder
Robert Linder

Reputation: 41

My Angle Math wrong why?

Right triangle

enter image description here

the image shows how it should add up! but when i try in code i get wrong answer why?

function myMath () {
  var H;  // hyp
  var O;  // opp
  var A;  // adj
  var T;  // angle
  var value;

  T = 42;
  H = 13;

  O = H * Math.sin(T);

  console.log(O); 

}

myMath()

so i added this more to the function missing a couple what would they be?

function myMath() {

        var H; // hyp
        var O; // opp
        var A; // adj
        var T; // angle
        var value;

        T = 42;
        H = 13;

        O = H * Math.sin(T * Math.PI / 180);
        //root.sinplate.textField_O.text = O;
        console.log("8.7 Answer " + O);

        T = 37;
        A = 10;

        O = A * Math.tan(T * Math.PI / 180);
        //root.sinplate.textField_O.text = O;
        console.log("7.5 Answer " + O);

        T = 41;
        A = 13;

        H = A / Math.cos(T * Math.PI / 180);
        //root.sinplate.textField_H.text = H;
        console.log("17.2 Answer " + H);
    }

what are the angles i am missing?

i tried this but it is wrong

H = 13;
        A = 5;

        T = A / Math.tan(H * Math.PI / 180);
        root.sinplate.textField_T.text = T;
        console.log("67.38 Answer " + T);

so i am looking for the correct format for t and a with only 2 numbers present

T=

and

A =

H = 13;
        O = 5;

        A =  H / Math.sin(O * 180 / Math.PI);
        root.sinplate.textField_A.text = A;
        console.log("12 Answer " + A);         // wrong

Upvotes: 2

Views: 107

Answers (1)

akuiper
akuiper

Reputation: 215127

You need to convert angle from degree to radian when using angle functions:

function myMath () {
    var H;  // hyp
    var O;  // opp
    var A;  // adj
    var T;  // angle
    var value;

    T = 42;
    H = 13;

    O = H * Math.sin(T * Math.PI / 180);

    console.log(O); 

}

myMath()

For the last case, you need the inverse cos, acos:

H = 13;
A = 5;

T = Math.acos(A / H) * 180 / Math.PI;
console.log("67.38 Answer " + T);

Upvotes: 5

Related Questions