C/C++ 三角函數

C/C++ 三角函數

C/C++ 三角函數 [GOOGLE: cmath sin]


資料來源:https://www.cplusplus.com/reference/cmath/sin/

https://www.cplusplus.com/reference/cmath/cos/

https://www.cplusplus.com/reference/cmath/tan/

https://www.cplusplus.com/reference/cmath/asin/

https://www.cplusplus.com/reference/cmath/atan/

https://www.cplusplus.com/reference/cmath/atan2/



線上編譯器:

https://www.tutorialspoint.com/compile_cpp_online.php
https://www.tutorialspoint.com/compile_c_online.php


sin(30)=0.5

/* sin example */
#include <stdio.h>      /* printf */
#include <math.h>       /* sin */

#define PI 3.14159265

int main ()
{
  double param, result;
  param = 30.0;
  result = sin (param*PI/180);
  printf ("The sine of %f degrees is %f.\n", param, result );
  return 0;
}
/*
The sine of 30.000000 degrees is 0.500000.
*/


cos(60)=0.5

/* cos example */
#include <stdio.h>      /* printf */
#include <math.h>       /* cos */

#define PI 3.14159265

int main ()
{
  double param, result;
  param = 60.0;
  result = cos ( param * PI / 180.0 );
  printf ("The cosine of %f degrees is %f.\n", param, result );
  return 0;
}

/*
The cosine of 60.000000 degrees is 0.500000.
*/


tan(45)=1

/* tan example */
#include <stdio.h>      /* printf */
#include <math.h>       /* tan */

#define PI 3.14159265

int main ()
{
  double param, result;
  param = 45.0;
  result = tan ( param * PI / 180.0 );
  printf ("The tangent of %f degrees is %f.\n", param, result );
  return 0;
}
/*
The tangent of 45.000000 degrees is 1.000000.
*/


arc sine(0.5)=30

/* asin example */
#include <stdio.h>      /* printf */
#include <math.h>       /* asin */

#define PI 3.14159265

int main ()
{
  double param, result;
  param = 0.5;
  result = asin (param) * 180.0 / PI;
  printf ("The arc sine of %f is %f degrees\n", param, result);
  return 0;
}
/*
The arc sine of 0.500000 is 30.000000 degrees.
*/


arc cosine(0.5)=60

/* acos example */
#include <stdio.h>      /* printf */
#include <math.h>       /* acos */

#define PI 3.14159265

int main ()
{
  double param, result;
  param = 0.5;
  result = acos (param) * 180.0 / PI;
  printf ("The arc cosine of %f is %f degrees.\n", param, result);
  return 0;
}
/*
The arc cosine of 0.500000 is 60.000000 degrees.
*/


arc tangent(1)=45

/* atan example */
#include <stdio.h>      /* printf */
#include <math.h>       /* atan */

#define PI 3.14159265

int main ()
{
  double param, result;
  param = 1.0;
  result = atan (param) * 180 / PI;
  printf ("The arc tangent of %f is %f degrees\n", param, result );
  return 0;
}
/*
The arc tangent of 1.000000 is 45.000000 degrees.
*/


arc tangent(10/-10)=135

/* atan2 example */
#include <stdio.h>      /* printf */
#include <math.h>       /* atan2 */

#define PI 3.14159265

int main ()
{
  double x, y, result;
  x = -10.0;
  y = 10.0;
  result = atan2 (y,x) * 180 / PI;
  printf ("The arc tangent for (x=%f, y=%f) is %f degrees\n", x, y, result );
  return 0;
}
/*
The arc tangent for (x=-10.000000, y=10.000000) is 135.000000 degrees.
*/

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *