在C语言便准库中,要使用三角函数需要把度转变为弧度的形式,准换公式 deg/180*pi
测试
#include <stdio.h>
#include <math.h>
#define My_Pi 3.14159
/********************************************************************************
* @fun My_Sin
* @brief sin求值
* @param 无
* @retval 无
* @author 之风
* @data 2019.11.4 晚
********************************************************************************/
float My_Sin(float deg)
{
return sin(deg/180*My_Pi);
}
/********************************************************************************
* @fun My_Cos
* @brief cos求值
* @param 无
* @retval 无
* @author 之风
* @data 2019.11.4 晚
********************************************************************************/
float My_Cos(float deg)
{
return cos(deg/180*My_Pi);
}
/********************************************************************************
* @fun My_Tan
* @brief tan求值
* @param 无
* @retval 无
* @author 之风
* @data 2019.11.4 晚
********************************************************************************/
float My_Tan(float deg)
{
return tan(deg/180*My_Pi);
}
int main (void)
{
float temp1=30;
float temp2=0;
temp2=My_Sin(temp1);
printf("My_Sin=%f\n",temp2);
temp2=My_Cos(temp1);
printf("My_Cos=%f\n",temp2);
temp2=My_Tan(temp1);
printf("My_Tan=%f\n",temp2);
return 0;
}
结果

2万+

被折叠的 条评论
为什么被折叠?



