Archived

This topic is now archived and is closed to further replies.

Barrager

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

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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 )

Share this post


Link to post
Share on other sites
math.h isn''t part of the C++ standard is what the difference is. However, it is part of the C standard so I believe you can be guaranteed that the contents of math.h are the same throughout different implimentations.

Share this post


Link to post
Share on other sites
ok so heres what i should do from what i got out of your posts

#include <cmath>

main ()
{
double I;// length of hypotenuse
double E;// equals the angle
double ans;
cin >> E;

ans=cos(E);
}

ok so what about the hypotenuse where does that come into play. the object of using sin and cos, is to figure out the hieght of a paralellagram by using only the measurements of it's angles and sides like this:
```````12
________________
\``````````````|`\```````````x`|`\```9
``\````````````|``\
```\___________|___\ a:60 degrees

how do i find x?



[edited by - barrager on November 18, 2003 11:16:38 AM]

[edited by - barrager on November 18, 2003 11:19:02 AM]

[edited by - barrager on November 18, 2003 11:20:29 AM]

Share this post


Link to post
Share on other sites
cos(a) = adj/hyp. You know the angle and the hypotenuse, so you need to solve for the adjacent side.

adj = hyp*cos(a), or using your numbers x = 9*cos(60).

However, because the computer uses radians in your program it should be:

x = 9*cos(Pi/3)

Share this post


Link to post
Share on other sites
quote:
Original post by YoshiN
cos(a) = adj/hyp. You know the angle and the hypotenuse, so you need to solve for the adjacent side.

adj = hyp*cos(a), or using your numbers x = 9*cos(60).

However, because the computer uses radians in your program it should be:

x = 9*cos(Pi/3)


actually it''s 9*sin60, he wants the height,so it''s the opposite side,not the adjacent.

Share this post


Link to post
Share on other sites
quote:
Original post by hpolloni
quote:
Original post by YoshiN
cos(a) = adj/hyp. You know the angle and the hypotenuse, so you need to solve for the adjacent side.

adj = hyp*cos(a), or using your numbers x = 9*cos(60).

However, because the computer uses radians in your program it should be:

x = 9*cos(Pi/3)


actually it''s 9*sin60, he wants the height,so it''s the opposite side,not the adjacent.



Whoops, read it wrong.

Share this post


Link to post
Share on other sites