+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Are there two sine and cosine ratios?

  1. #1
    krahny's Avatar
    krahny is offline x10Hosting Member krahny is an unknown quantity at this point
    Join Date
    Nov 2009
    Posts
    25

    Question Are there two sine and cosine ratios?

    When I enter sin(0) in a calculator, it gives me 0, and sin(90) gives me 1, just like I'd expect it to. But, when I use javascripts Math.sin() and Math.cos() functions, they give me completely different results. I think they might have something to do with pi, instead of an angle.

    Could someone please help me?

    Thanks.

  2. #2
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: Are there two sine and cosine ratios?

    In Javascript (and PHP) the input for the sin functions are in radians rather than degrees. A radian is just a different way of measuring angles and is linked to circular calculations. There are 2pi radians in a complete circle, so 360˚ = 2pi radians and 180˚ = pi radians. The simplest way to convert one to the other is like so:
    Code:
    If you intend to do this:
    Math.sin(number);
    Change it to this:
    Math.sin((Math.PI * number)/180);
    Also remember that doing inverse sin functions will give you an answer in radians that you may then want to convert to degrees.
    Last edited by lemon-tree; 09-27-2010 at 01:09 PM.

  3. #3
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,228

    Re: Are there two sine and cosine ratios?

    lemon-tree: This is actually true for calculators too. Their default setting is Radian, however most schools make kids change the setting to Degree so they don't run into this problem. :P
    Neil Hanlon | x10Hosting Support Representative
    Neil[at]x10hosting.com
    █ I'm always happy to help. Just ask a question in Free Hosting
    Terms of Service IRC

  4. #4
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: Are there two sine and cosine ratios?

    Wasn't the default on my lump of a calculator, at least I don't think it was. Don't fancy resetting it to test and lose the data on it.
    Last edited by lemon-tree; 09-27-2010 at 04:04 PM.

  5. #5
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Are there two sine and cosine ratios?

    My first calculator:

    Nothing is always absolutely so.

  6. #6
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: Are there two sine and cosine ratios?

    Retro
    Anyway, krahny is this working for you now? If you need any further explanation of the the implementation or the theory then one of us will be happy to help.

  7. #7
    essellar's Avatar
    essellar is offline Community Advocate essellar has a spectacular aura about
    Join Date
    Feb 2010
    Location
    Toronto, Ontario, CA
    Posts
    1,153

    Re: Are there two sine and cosine ratios?

    @descalzo: What's that, a 45 maybe? I have no idea how old you are, but I remember paying more for my first HP than I paid for my first (used) car. Never could get the hang of RPN -- I became a TI man by '77 (the TI 59 was another half-a-grand machine when I bought it). And, to get back to the question at hand, it defaulted to degree mode as well.
    “Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
    "It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)

  8. #8
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Are there two sine and cosine ratios?

    HP 35. Originally ('72) cost $395 (about $2000 in today's dollars). Was at U.C. Berzerkly.

    Considering the laptop/notepad you can get today for $395 it is mind boggling.
    Nothing is always absolutely so.

  9. #9
    essellar's Avatar
    essellar is offline Community Advocate essellar has a spectacular aura about
    Join Date
    Feb 2010
    Location
    Toronto, Ontario, CA
    Posts
    1,153

    Re: Are there two sine and cosine ratios?

    Ah, a fellow fogie. Good to know I'm not the only one. (And I'd bet we're the only ones here who remember Al Capp's characters. Schmoo's cool, but I was into Joe Btfsplk -- he kinda reminded me of me. And as a Canadian, often standing waist-deep or deeper in the snow, I had a deep feeling of kinship with the good people of Lower Slobovia.)
    “Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
    "It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)

  10. #10
    krahny's Avatar
    krahny is offline x10Hosting Member krahny is an unknown quantity at this point
    Join Date
    Nov 2009
    Posts
    25

    Re: Are there two sine and cosine ratios?

    Thanks, Lemon-tree, that code worked.


+ Reply to Thread
Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers