Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Sine, cosine, tangent.

Posted on 1998-10-01
15
323 Views
Last Modified: 2012-08-13
I would like to calculate the sine cosine and tangent of some numbers.  What are the functions that let me to do that?  I am new to C++ and English so please be clear.  Thank you.
0
Comment
Question by:theperson
  • 4
  • 3
  • 3
  • +3
15 Comments
 

Author Comment

by:theperson
ID: 1174230
Edited text of question
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1174231
Here are the names of the functions that do what you ask:
sin
cos
tan

For the arc sine, arc cosine, and arc tangent look into:
asin
acos
atan

All of these functions are declared in the "math.h" header file, so make sure you add:

#include <math.h>

to the top of your source code.

Also, remember that the numbers you provide the function are in radians, not degrees.  To convert from degrees to radians, multiply the number of degrees by:
0.01745329252 (roughly)  :-)

Here's an example.

Let's say you want to calculate the sine of 234 (degrees).  You would use:

result = sin (234 * 0.01745329252);

Consider definining a constant double at the top of the source code that looks like:

const double DEG2RAD 0.01745329252;

or something like that.  That way, you don't have to remember those arcane numbers.

Here is an example that uses the DEG2RAD constant:

sin (234 * DEG2RAD);

See how much easier that is to read?

If you have any additional questions, please ask.
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1174232
Thresher you mean
const double DEG2RAD = 0.01745329252;

Good answer otherwise

BTW the maths relies on 2 * PI radians in 360 degrees
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 22

Expert Comment

by:nietod
ID: 1174233
thresher_shark, its bad enough that ozo doesn't ever answer, do you have too?  What is this world coming to?  Greed is the prime motivating force for progress, without it the universe will come to a screetching halt.  : - )
0
 
LVL 2

Expert Comment

by:Hippy
ID: 1174234
If you plan on using these functions in anything fast, say graphics routines, realtime calculations etc.  Use them to make a lookup table first, then just referance the lookup table, this way you only have to caculate things once, at the start of your program.

Hippy.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1174235
Its often not worth it these days.  On a pentium, the transcental function can take as little as about 20 clock cycles and at worst about 150 clock cycles.  Your look-up code is likely to take longer than that.  It certainly isn't going to be much faster.
0
 
LVL 3

Expert Comment

by:daitt
ID: 1174236
I think that it's enough for all of you to chat here. The text of Thresher is really a good answer, but if he didnot want to answer, I'll do. I want to stop this question.
0
 
LVL 3

Expert Comment

by:daitt
ID: 1174237
I'm sorry, but my answer has push Thresher out. Here is his answer:

"
Here are the names of the functions that do what you ask:
sin
cos
tan

For the arc sine, arc cosine, and arc tangent look into:
asin
acos
atan

All of these functions are declared in the "math.h" header file, so make sure you add:

#include <math.h>

to the top of your source code.

Also, remember that the numbers you provide the function are in radians, not degrees.  To convert from degrees to radians, multiply the number of degrees by:
0.01745329252 (roughly)  :-)

Here's an example.

Let's say you want to calculate the sine of 234 (degrees).  You would use:

result = sin (234 * 0.01745329252);

Consider definining a constant double at the top of the source code that looks like:

const double DEG2RAD 0.01745329252;

or something like that.  That way, you don't have to remember those arcane numbers.

Here is an example that uses the DEG2RAD constant:

sin (234 * DEG2RAD);

See how much easier that is to read?

If you have any additional questions, please ask.
"
0
 
LVL 22

Expert Comment

by:nietod
ID: 1174238
Well that's a useful answer that tells theperson so much that he/she didn't know.
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1174239
Answers2000 - You're right, careless mistake :-)  I have recently switched over from "#define"s to "const"s so I occasionally forget the '=' sign.

daitt - It is usually considered bad form to "answer" a question using someone else's comments.  I cannot use EE to the same extent that I used to be able to (only able to log on about once a day for half hour to hour) because I have school and a life.  That means it might take me some time to respond to comments.  Please see my profile.

nietod - I think I am going to go back to actually answering questions again.  I was just giving the "answer-in-comment" approach a try because it would keep the question open so the customer could get more response from other experts.  It's unfortunate that people "answer" the question with someone else's comment(s).
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1174240
theperson - Please select the "Reject" or "Re-open" current answer (I am not sure of the exact terminology) from your list of options.  It is separate from the rest of the buttons.
0
 

Author Comment

by:theperson
ID: 1174241
Everyone has been most helpful.  Thresher_shark: I have rejected the current answer.  Now what do us do?
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1174242
theperson - wait for Thresher to post a dummy answer, then grade that
0
 
LVL 6

Accepted Solution

by:
thresher_shark earned 200 total points
ID: 1174243
Thank you very much.  If you have any further questions regarding my answer, please feel free to ask them.
0
 

Author Comment

by:theperson
ID: 1174244
No, there are no other questions about this, I have figured it all out now.  Thank you every one!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C++ Language error 28 241
gdb doesn't stop on breakpoint 2 89
Need some help with mailto 16 20
One named event, multiple event handlers 2 24
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question