#1
  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. #2
  3. 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.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    172
    Rep Power
    11
    Thanks Alot :)
  6. #4
  7. 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.
    thnanks alot for your advice but still have problem with the radians and degree convertions
    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
  8. #5
  9. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2004
    Posts
    1,676
    Rep Power
    133
    Multiply the degrees by pi and divide by 180.

    Comments on this post

    • kicken agrees : simple math
    Any advertisement triggered by IntelliTxt in this post is not endorsed by the author of this post.
  10. #6
  11. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,183
    Rep Power
    2222
    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:
    360 degrees == 2*PI radians
    180 degrees == PI radians
    1 degree == PI/180 radians
    1 radian == 180/PI degrees

    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 11:03 AM.
  12. #7
  13. Commie Mutant Traitor
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2004
    Location
    Alpharetta, GA
    Posts
    1,806
    Rep Power
    1570
    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
     
    inline double deg2rad(double degrees)
    {
        return degrees * DEG_TO_RAD;
    }
     
    inline double rad2deg(double radians)
    {
        return radians * RAD_TO_DEG;
    }


    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 11:46 AM.
    Rev First Speaker Schol-R-LEA;2 JAM LCF ELF KoR KCO BiWM TGIF
    #define KINSEY (rand() % 7) λ Scheme is the Red Pill
    Scheme in Short Understanding the C/C++ Preprocessor
    Taming Python A Highly Opinionated Review of Programming Languages for the Novice, v1.1

    FOR SALE: One ShapeSystem 2300 CMD, extensively modified for human use. Includes s/w for anthro, transgender, sex-appeal enhance, & Gillian Anderson and Jason D. Poit clone forms. Some wear. $4500 obo. tverres@et.ins.gov
  14. #8
  15. 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
    1 rad = 57.692 degree.
    thaank alot for your .
    i really enjoy your lectures.

IMN logo majestic logo threadwatch logo seochat tools logo