c/c++三角函数使用

在C/C++中,sin、cos、tan等函数接受的参数是弧度而不是角度。要计算角度的三角函数值,需将角度转换为弧度,转换公式为:弧度=角度*3.1415926/180.0。文章提供了示例代码展示如何使用math库进行转换并计算三角函数值。
摘要由CSDN通过智能技术生成

简介

在C/C++ sin 的参数与我们平常数学三角函数理解的不一样.

C/C++语言中sin、cos、tan、asin、acos、atan 的参数是 弧度,而不是角度. 所有我们计算一个角度的sin、cos、tan、asin、acos、atan 值时,应先转成弧度值.

公式如下

弧度 = 角度 * 3.1415926 / 180.0

#include <cmath>
//sin
int angle1 = 30;                   // 角度
sin(angle1 * 3.1415926 / 180.0);   // 获得 30度对应的 sin 值 0.5

//cos
int angle2 = 120;                // 角度值
cos(angle2 * 3.1415926 / 180.0)  // 120 度的 cos 值 -0.5

//tan
std:cout << tan(angle2 /180*3.1415926) << std::endl;

//asin
asin (angle2 * 3.1415926 / 180.0);

//acos
int angle3 = 120;                               // 角度
float cosr = cos(angle3 * 3.1415926 / 180.0)    // 120 度的 cos 值-0.5
acos(cosr) * 180 / 3.1415926;                  // 计算返回 角度值 应是120 

//atan
//atan函数输出的是弧度! 如果想进行atan运算得到角度,需要乘以(180/PI)把弧度转为角度
float atanValue1 = atan(1.0f);  
float atanValue2 = atan(1.0f)*180.0f/PI; 
cout<<"atan(1) = "<<atanValue1<<endl; //输出弧度
cout<<"(atan(1.0))*180/PI = "<<atanValue2<<endl; //输出角度
          

下面是摘自网络搜集的资料,很容易快速的理解与案例和公式:
在这里插入图片描述

扩展资料:

一、常用的诱导公式

任意角α与 -α的三角函数值之间的关系:

sin(-α)=-sinα.

cos(-α)=cosα.

tan(-α)=-tanα.

cot(-α)=-cotα.

sec(-α)=secα.

csc (-α)=-cscα.

二、角度制下的角的表示:

sin(180°-α)=sinα.

cos(180°-α)=-cosα.

tan(180°-α)=-tanα.

cot(180°-α)=-cotα.

sec(180°-α)=-secα.

csc(180°-α)=cscα.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

路过的小熊~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值