### Thread: How to use sin,cos,tan inverse in c or c++

1. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Feb 2004
Posts
172
Rep Power
11

#### How to use sin,cos,tan inverse in c or c++

Hello ...
.I have this program to calculate some math equations but i want it to be better using some inverses !

so any idea how to use Tan-1(x) , Sin-1(x) ??
2. No Profile Picture
Contributing User
Devshed Intermediate (1500 - 1999 posts)

Join Date
Feb 2004
Location
San Francisco Bay
Posts
1,939
Rep Power
1313
You can use atan(), asin(), and acos(). Those are the respective inverses of tan, sin, and cos.
3. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Feb 2004
Posts
172
Rep Power
11
Thanks Alot :)
4. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2006
Posts
10
Rep Power
0

#### how is it done in radians

Originally Posted by Lux Perpetua
You can use atan(), asin(), and acos(). Those are the respective inverses of tan, sin, and cos.
this is what we have at hand

# include <stdio.h>
# include <math.h>
# include <stdlib.h>

int main()

{
printf("%f", atan (30));
return 0;

}
// the 30 is in degrees. how do i solve this issue. awiating you support and advice
5. Multiply the degrees by pi and divide by 180.

• kicken agrees : simple math
6. Review a basic trigonometry text, because your conception of arctan is wrong as well.

In a circle, you have 360 degrees or 2*PI radians. Hence:

There are your conversion factors for degrees to radians and back again. You also see the basic procedure for deriving conversion factors.

Now, for your confused concept of trig and inverse trig functions. The trig functions take an angle argument and they return the ratio of two of the sides of a right triangle that contains that angle. Which two of the three sides of that triangle are used is determined by which trig function you use. Refer to a text to see what they are.

An inverse trig function (eg, atan) takes a ratio as an argument and returns the angle that that ratio represents; ie, it takes the associated trig function in the opposite direction -- that is what makes it an inverse function. An important caveat to keep in mind is that the angle returned by an inverse trig function only ranges over 180 degrees, so you have to look at the two numbers in the ratio to figure out which quadrant of that circle that angle lies in and hence exactly what that angle was -- again, read up on this in a trig textbook; the pictures should explain it better than my words could (no, I am not being facetious; a graphical representation communicates a lot in this area of math).

So, your sample code is wrong, because you would not pass an angle to atan().

Now, to get the value of PI, consider this: atan(1.0) == 45 degrees == PI/4.
So if you take the atan() of 1.0 and multiply it by 4, you will get PI. Hence, in your initialization code you should declare a global variable dPi and assign it thus:
Code:
```#include <math.h>

double dPi;

int main(void)
{
dPi = 4.0 * atan(1.0);

return 0;
}```
Oh, and in the future please use code tags to post code. Just stick your code between [code] and [/code].

PS
Don't be afraid to study up on trig. It's really quite simple. I taught myself one summer and I'm no genius, not by a long shot.

The reason for radians is that the method for calculating the trig functions (Maclaurin series, a special form of Taylor series -- you'll cover these in 3rd semester calculus) depends on the angle being in radians. Also, throughout calculus you will be dealing with angles being measured in radians, so now's as good a time as any to start getting used to it.
Last edited by dwise1_aol; March 20th, 2006 at 12:03 PM.
7. Originally Posted by Dave Sinkula
Multiply the degrees by pi and divide by 180.
Since you presumably are doing this in a number of places, and probably need to convert freely between them in both directions, you would be wise to write conversion functions:

C Code:
```
#include <math.h>  // or <cmath> for C++

// Sombunall versions of math.h already define M_PI
#ifndef M_PI
// You can extend this approximation as far as you need to;
// this version was copied from the MINGW GCC headers
#define M_PI 3.14159265358979323846
#endif

#define DEG_CIRCLE 360
#define DEG_TO_RAD (M_PI / (DEG_CIRCLE / 2))
#define RAD_TO_DEG ((DEG_CIRCLE / 2) / M_PI)

// this assumes that your compiler supports C99 or C++
// otherwise, you can use macros to get the same result

{
}

{
}```

This is one of those cases (like the isodd()/iseven() pair, or the previously mentioned constant M_PI) where what would seem an obviously common function is mysteriously absent from the standard library... while loose cannons like gets() get perpetuated indefinitely. Go figure. HTH.
Last edited by Schol-R-LEA; March 20th, 2006 at 12:46 PM.
8. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2006
Posts
10
Rep Power
0

#### Thanks

thanks pals. i tried tried another approach and it work