Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将值从弧度转换为度_Python_Function_Degrees_Radiant - Fatal编程技术网

Python 将值从弧度转换为度

Python 将值从弧度转换为度,python,function,degrees,radiant,Python,Function,Degrees,Radiant,我已对以下功能进行了编程: def horizontal(yAngle, yAcceleration, xAcceleration): a = (math.cos(yAngle)*yAcceleration)-(math.sin(yAngle)*xAcceleration) return a 问题如下:math.cos和math.sin返回一个弧度值。我想要这个值,我从math.cos和math.sin中得到,以度为单位 所以计算应该是这样的: 首先,以弧度为单位输出mat

我已对以下功能进行了编程:

def horizontal(yAngle, yAcceleration, xAcceleration):
     a = (math.cos(yAngle)*yAcceleration)-(math.sin(yAngle)*xAcceleration)
     return a
问题如下:math.cos和math.sin返回一个弧度值。我想要这个值,我从math.cos和math.sin中得到,以度为单位

所以计算应该是这样的: 首先,以弧度为单位输出math.cosx和math.sinx中的值,而不是x。这意味着末尾有两个值,因为它们是两个不同的函数,它们得到相同的值。这两个值现在应转换为度。然后,应按如下方式进行计算:a=cos的值(单位:度)*YAAcceleration-sin的值(单位:度)*XAAcceleration

我发现Python中有math.degrees和math.radians函数。我只是尝试了不同的选择,但没有一个是正确的。有人能告诉我如何正确使用它吗


我怎样才能到达这里?谢谢你帮助我

度=2π*弧度,因此您可以使用:

def水平加速度、Y加速度、X加速度: a=2*math.pi*math.cosyAngle*yacelleration-2*math.pi*math.sinyAngle*xacelleration 归还

祝你好运

您需要修复格式,因为我的手机上没有代码块选项。

def cos_degx: 返回math.cosmath.radiansx def sin_degx: 返回math.sinmath.radiansx
请注意,sin和cos不返回弧度值,它们采用弧度参数并返回无量纲值,尽管弧度在技术上是无量纲的。

这是重复的-这是否回答了您的问题?1弧度=180/π,在你的问题中加上这个。谢谢你的这两个函数。我现在如何使用它们呢?如果你把它们复制到代码开头的某个地方,你可以调用a=cos_degyAngle*yAcceleration-sin_degyAngle*xAcceleration,例如。我想这不是我真正想要的。我的意思是:我从m.cosx得到一个弧度值。然后应将该弧度值转换为度,然后插入到方程式中。@mathflower math.cosx不返回弧度值,而是返回无量纲值−1比1。如果你愿意,你可以在上面调用math.degrees,但那没有什么意义。在math的文档中,math.cosx返回x弧度的余弦。好吧,我得到一个值x。这将写入函数m.cos。我从中得到的值,应该转换成度,然后插入到方程中。