Basic Trigonometric functions – CSKC
Sign In

Search

Code Learning #CPP#2130    siteicon   siteicon  

Basic Trigonometric functions

Using trigonometric functions like sin, cos and tan etc. in c++

Learning Objectives

  • Learning to use basic trigonometric functions.

Source Code

TC++ #2130

Source Code

×

Ask AI About This Code

Default Prompt that is passed along with the code is given below, You can write your own prompt if you so desire.



×

Test CPP

Code Understanding

const double PI=3.1416; //constant PI has been initialised with a double value here
int a=90,b=0,c=45;  //These values have been given in degrees.

double ar=a*PI/180;
double br=b*PI/180;
double cr=c*PI/180;
These are statements for conversion of degree values to radians using the conversion 1 degree = PI/180 radians. This conversion is done so that the correct input value for trigonometric functions can be achieved.

cout<<“sin(“<<ar<<“) = “<<sin(ar)<<endl;
cout<<“cos(“<<br<<“) = “<<cos(br)<<endl;
cout<<“tan(“<<cr<<“) = “<<tan(cr)<<endl;
Here we get sin, cos and tan of corresponding inputs in radians.

 

Notes

  • C++ supports many other trigonometric functions like arc form of sin/cos/tan and hyperbolic trigonometric functions. One can check the reference from 
    http://www.cplusplus.com/reference/cmath/
  • Careful use of these functions are required as some inputs may yield undefined values and for some inputs the data precision limits may not allow correct output values.

Common Errors

  • Student often confuse between the degree and radian input values. Just remember that 2.PI radians is equal to 360 degree for easy conversion. Radian is angle covered in a circle when the length of covered arc by the angle is equal to radius.  https://en.wikipedia.org/wiki/Radian


Suggested Filename(s): math-trig.cpp



Share

Created: 3-Jan-2018 03:20 | Updated: 3-Jan-2018 17:07|