-
November 7th, 2001, 10:32 AM
#1
sin cos tan
I'm trying to do some pie chart math,
and doing so I'm using the sin() and cos()
functions.
My delima is, if I use sin() on an angle of 18
for example, the sin() function returns
-0.75098724677168
if you put 18 in Calculator and press the SIN
button, it gives you
0.30901699437494742410229341718282
The one from Calculator is the one I'm after
to get my math right, what's up?
Also, if you go to the def of sin in MSDN
it shows this little snipplet:
Example
/* SINCOS.C: This program displays the sine, hyperbolic
* sine, cosine, and hyperbolic cosine of pi / 2.
*/
#include <math.h>
#include <stdio.h>
void main( void )
{
double pi = 3.1415926535;
double x, y;
x = pi / 2;
y = sin( x );
printf( "sin( %f ) = %f\n", x, y );
y = sinh( x );
printf( "sinh( %f ) = %f\n",x, y );
y = cos( x );
printf( "cos( %f ) = %f\n", x, y );
y = cosh( x );
printf( "cosh( %f ) = %f\n",x, y );
}
Output
sin( 1.570796 ) = 1.000000
sinh( 1.570796 ) = 2.301299
cos( 1.570796 ) = 0.000000
cosh( 1.570796 ) = 2.509178
If I punch in the numbers in Calculator, none of
this works out right. Even based on solely the
bottom output, Calc says the sin(1.570796) is
0.027412127890540702705615104925336 and not
1.000000000.
Thanks...
*DM*
AIM/AOL: EdisonCPP
ICQ: 39184886 - ID EdisonCPP
Email: edisoncpp@carolina.rr.com
sedison@protronix.com
-
November 7th, 2001, 10:43 AM
#2
Re: sin cos tan
your calculator is using the angle as DEGREES not RADIANS.
It should have an option to change this.
-
November 7th, 2001, 10:46 AM
#3
Re: sin cos tan
The difference is that what you get when you do sin(18) is in fact sin (18 Radians) which is different from sin(18 degrees).
If you put your calculator into Rad mode and then repeat sin(18) you get the answer -0.75098.
A lot of maths calculations are based on Radians and are expressed in terms of pi.
2*pi = 360 degrees
=>
1 Radian = 57.2958 degrees
pi = 180 degrees
pi/2 = 90 degrees
sin(90) = sin(pi/2) = 1.0
The MSDN help for sin does sya that the parameter x is the 'Angle in Radians'
Regards
Alan
-
November 7th, 2001, 10:46 AM
#4
Re: sin cos tan
sin is work with radians and your calcularor - with degrees! Set calculator to radians and see the same results
Rating isn't important...But gurus respect it and keep high
-
November 7th, 2001, 10:46 AM
#5
Re: sin cos tan
So how do I use Degrees with sin()?
You were right about calc.exe, it
then gave the same result.
*DM*
AIM/AOL: EdisonCPP
ICQ: 39184886 - ID EdisonCPP
Email: edisoncpp@carolina.rr.com
sedison@protronix.com
-
November 7th, 2001, 10:50 AM
#6
Re: sin cos tan
1 degree = pi/180 radians;
Store it as a constant and multiply before calling sin,cos etc.
-
November 7th, 2001, 10:54 AM
#7
Re: sin cos tan
float angle_in_degrees = 18.0f;
//
// convert degrees to radians ... 3.14159 (PI) radians = 180 degrees
//
float angle_in_radians = angle_in_degrees * 3.14159f/ 180f;
//
//
// use : sin(angle_in_radians);
//
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|