Jump to content

How to properly use trig functions in C++

- - - - -

  • Please log in to reply
2 replies to this topic

#1
Daftatt

Daftatt

    Newbie

  • Members
  • Pip
  • 4 posts
Can someone post some examples of using sine/cosine/tangent and other trig functions in C++, I can't seem to figure out how to get it to work.

I'm used to using trig functions in the TI calculator where it's in BASIC and mega simple, but C++ has the integer-float discrepancy and I can't figure it out (because trig functions almost always have a float outcome).

#2
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
Here's a list of those functions and some more and each comes with a provided sample code.
A conclusion is where you got tired of thinking.
#define class struct    // All is public.

#3
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
One thing I've noticed is that most people learn trig functions in degrees, but in most programming languages they are in radians. As a result, sin(90) is giving you the sine of 90 radians, not 90 degrees. If you are thinking of x as being in degrees, you would do sin(x*pi/180.0).
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users