Thread: sin() and cos() that use degrees

  1. #1
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057

    Arrow sin() and cos() that use degrees

    Hi all,

    I was wondering if anyone knew of versions of sin() and cos() that use degrees. RHIDE's sin() and cos() use radians. I know how to convert between radians and degrees, but it doesn't work.

    When I display a bitmap at the equivalent of 90 degrees, it's slightly off, because (I assume) of inaccuracies in converting between radians and degrees. Or is it inaccuracies with floating point numbers? Either way, could someone point me to a degrees version if cos() and sin()? I already tried using google but didn't get too much information.

    DWK

  2. #2
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    You tried this? Make sure you're using doubles they have double precision.

    Code:
    double sind(double angle)
    {
    	double angleradians = angle * M_PI / 180.0f;
    	return sin(angleradians) * M_PI / 180.0f;
    }
    salem knows best

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well it's down to inaccuracies for sure. Besides, any degree version will simply call the radian version behind your back without you realising it, so it doesn't save anything.

    Or you could define
    Code:
    double sintable[90];
    Making sure the cardinal points are set correctly, and using a loop calling sin() to initialise the rest.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Okay, thanks. I'll try that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with cos, sin fuctions
    By xxxhunter in forum C Programming
    Replies: 7
    Last Post: 11-16-2007, 03:33 AM
  2. Help with cos, sin and tan^-1 (arctan);
    By xIcyx in forum C Programming
    Replies: 15
    Last Post: 04-23-2007, 09:14 AM
  3. Help creating function of sin cos and tan
    By Niz in forum C Programming
    Replies: 12
    Last Post: 01-09-2007, 05:55 PM
  4. Sin() and Cos() Problem
    By Grantyt3 in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 05:35 PM
  5. integral of 1/x
    By Silvercord in forum A Brief History of Cprogramming.com
    Replies: 43
    Last Post: 03-19-2004, 07:47 AM