sin() and cos() that use degrees

This is a discussion on sin() and cos() that use degrees within the C Programming forums, part of the General Programming Boards category; Hi all, I was wondering if anyone knew of versions of sin() and cos() that use degrees. RHIDE's sin() and ...

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

    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,220
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    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, 02: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, 04: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, 06:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21