Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Confusion with Math.toDegrees() and Math.toRadians(). Please help.

  1. #1
    Junior Member marksquall's Avatar
    Join Date
    Jan 2009
    Posts
    27
    My Mood
    Fine
    Thanks
    0
    Thanked 1 Time in 1 Post

    Question Confusion with Math.toDegrees() and Math.toRadians(). Please help.


    Dear administrators and members,

    A greeting of peace.

    I hope everyone is in good health upon reading this thread.

    I am currently working on a simple program that uses trigonometric laws like sine laws. I first try to write this simple codes first:

    double angle = 60;
    System.out.println( Math.sin(Math.toDegrees(angle) );

    Then the output is: 0.7475(something)

    I wonder why the output is 0.7475(something)? BUT, when I tried pressing sin 60 on my scientific calculator (in degrees mode as usual) the answer is 0.8660(something).

    Then later, I tried to use toRadians() method in Math class:

    double angle = 60;
    System.out.println( Math.sin(Math.toRadians(angle) );

    Then that is the time I got the 0.8660 (something) answer.

    I am just a little confused. My scientific calculator is in degrees mode, that is why I am expecting the same result if I will use the toDegrees() method, but why it did not?

    Please enlighten me. Did I miss something?


    Respectfully Yours,

    MarkSquall



  2. #2
    Junior Member
    Join Date
    Jun 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Confusion with Math.toDegrees() and Math.toRadians(). Please help.

    Hi,

    for Math.sin(doulbe a), a is an angle, in radians (pls refer to in API document), that's why sin(Math.toRadians(angle)) works.

  3. #3
    Junior Member
    Join Date
    Jun 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Confusion with Math.toDegrees() and Math.toRadians(). Please help.

    one more thing, following words are from API document, FYI.
    about toDegrees, "The conversion from radians to degrees is generally inexact; users should not expect cos(toRadians(90.0)) to exactly equal 0.0. "

  4. #4
    Junior Member marksquall's Avatar
    Join Date
    Jan 2009
    Posts
    27
    My Mood
    Fine
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Confusion with Math.toDegrees() and Math.toRadians(). Please help.

    Dear Ms. ivy,

    I already read the Java API documentation, and it's a great help for some useful definition. BUT, I just wondered why toRadians() is the one gave me the correct answer (as the one in my scientific calculator) than toDegrees() .

    Is it not if I press sin 60 in my scientific calculator, 60 is already (or "converted") in degrees (since my calculator is in DEG mode)?

    But anyway, a million thank you and more power.

    Warm regards,

    MarkSquall

Similar Threads

  1. Math Drill
    By Java Neil in forum What's Wrong With My Code?
    Replies: 11
    Last Post: February 5th, 2011, 01:12 AM
  2. Math Problem
    By kidsforsale in forum What's Wrong With My Code?
    Replies: 11
    Last Post: September 14th, 2010, 04:09 PM
  3. i can run my program but the math doesnt come otu
    By pairenoid in forum What's Wrong With My Code?
    Replies: 0
    Last Post: May 7th, 2010, 01:39 PM
  4. Question on my math
    By SwEeTAcTioN in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 25th, 2009, 05:42 PM
  5. Math in Java?
    By [Kyle] in forum Java Theory & Questions
    Replies: 3
    Last Post: September 23rd, 2009, 12:21 PM