Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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 2.7 角上的三角形函数_Python 2.7_Function - Fatal编程技术网

Python 2.7 角上的三角形函数

Python 2.7 角上的三角形函数,python-2.7,function,Python 2.7,Function,我需要一个作用于角度(例如度,但也可能是弧度)的函数,包括以下内容(它必须是连续的,我只写下一些关键值来理解行为): 这是一个简单的三角波 某些模块中是否已经存在任何内容,或者我是否需要自己创建它? 例如,像这样(又快又脏): def toTriangle(角度): 如果角度=0: t=(角度/90.) elif角度=90: t=2-(角度/90.) elif角度=180: t=-(3-(角度/90.)) 其他: t=-(4-(角度/90.)) 返回t 感谢DeepSpace提供您的建议,但它不

我需要一个作用于角度(例如度,但也可能是弧度)的函数,包括以下内容(它必须是连续的,我只写下一些关键值来理解行为):

这是一个简单的三角波

某些模块中是否已经存在任何内容,或者我是否需要自己创建它?
例如,像这样(又快又脏):

def toTriangle(角度):
如果角度<90且角度>=0:
t=(角度/90.)
elif角度=90:
t=2-(角度/90.)
elif角度=180:
t=-(3-(角度/90.))
其他:
t=-(4-(角度/90.))
返回t

感谢DeepSpace提供您的建议,但它不是开箱即用的:

from scipy.signal import sawtooth
sawtooth(0)
Out[4]: array(-1.0)
这里有一个不那么快的解决方案:

def toTriangle(angle):
    import math
    tr = 1-4*math.fabs(0.5-math.modf(0.25+0.5*angle%(2*math.pi)/math.pi)[0] )
    return t
()

from scipy.signal import sawtooth
sawtooth(0)
Out[4]: array(-1.0)
def toTriangle(angle):
    import math
    tr = 1-4*math.fabs(0.5-math.modf(0.25+0.5*angle%(2*math.pi)/math.pi)[0] )
    return t