Sin and Cos. how do i use them in C++

Started by
15 comments, last by Barrager 20 years, 4 months ago
ok i need to find the height of a qudralateral using only the measurements of the sides and the angles. some how i need to use sin and cos yet i;ve never used any of those type of equations in C++ is it possible? how? also i''ve never really used cos and sin on a calculator so i have no clue how to even setup the equation. all i know is sin and cos find the langth of the oppsite and the adjacent using the hypotenuse and the other given side.
Life is but a Rollercoster, so sit back shut up and enjoy the ride.
Advertisement
float angle; // in radians
float x = cos(angle);
yeh and don''t forget... #include <math.h>
And don't forget the angle is measured in radians. To convert degrees to radians, multiply it by Pi/180. To convert from radians to degrees multiply by the inverse (180/Pi).

EDIT: and if you are using C++, you should include not math.h

[edited by - YoshiN on November 17, 2003 1:59:52 PM]
-YoshiXGXCX ''99
quote:Original post by YoshiN
EDIT: and if you are using C++, you should include not math.h


Whats the difference?

quote:Original post by SpaceDude
Whats the difference?


math.h is a depreciated header. if you''re using c++ you should be using cmath (no .h)

-eldee
;another space monkey;
[ Forced Evolution Studios ]

::evolve::

Do NOT let Dr. Mario touch your genitals. He is not a real doctor!

-eldee;another space monkey;[ Forced Evolution Studios ]
quote:Original post by eldee
quote:Original post by SpaceDude
Whats the difference?

math.h is a depreciated header. if you''re using c++ you should be using cmath (no .h)


Got any more info on that? I''m interested to know what the actual difference is...
quote:Original post by SpaceDude
quote:Original post by eldee
quote:Original post by SpaceDude
Whats the difference?

math.h is a depreciated header. if you''re using c++ you should be using cmath (no .h)


Got any more info on that? I''m interested to know what the actual difference is...


The difference is that cmath adds a few extra #defines and stuff. If you want specifics, just open cmath from your C++ compiler''s include folder. You''ll notice that it actually includes the math.h header.


"Skepticism.... that great rot of the intellect." - V.H.
Bah, what does HE know?


Albekerky Software
"Skepticism.... that great rot of the intellect." - V.H.Bah, what does HE know?Albekerky Software
Actually, the differences are that <math.h> is deprecated and with <cmath> all symbols are under the std namespace.

http://www.cplusplus.com/doc/ansi/hfiles.html


[edited by - Alvaro on November 17, 2003 9:47:13 PM]
Also, cmath overloads the functions so calling cos() with a float parameter actually calls cosf()

VERY useful for templates.

- Scott "me22" McMurray
( email/MSN me22@fastmail.ca ICQ 37213887 )

This topic is closed to new replies.

Advertisement