gpt4 book ai didi

c# - 如何实现这个振荡功能

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:45:37 25 4
gpt4 key购买 nike

什么是实现此振荡功能的快速方法。签名看起来像这样:

public static double Calculate(UInt64 currentCounter, uint duration, uint inDuration, uint outDuration)

结果应该是 currentCounter 增加的两倍,在 0 和 1 之间振荡。振荡速度由 duration 参数(单次振荡的滴答数)定义。类似地,上升和下降速度是通过 inDUrationoutDuration (inDUration + outDuration) 定义的。

alt text http://img252.imageshack.us/img252/9457/graphuf.jpg

该图的 x 轴当然是 currentCounter

最佳答案

正如评论者指出的那样,您必须了解这些功能。
程序结构类似于:

// Use modulo to get the counter within the range of the first duration
var phaseCounter = currentCounter % duration;

// Use the appropriate function
if( phaseCounter < inDuration )
{
return InFunction( phaseCounter, inDuration );
}
if( phaseCounter > duration - outDuration )
{
// Normalize the phaseCounter to the domain of definition for OutFunction()
var outDurationOffset = duration - outDuration;
return OutFuntion( phaseCounter - outDurationOffset, outDuration );
}
return 0;

如您所见,您必须填写 InFunction()OutFunction()
它们都有两个参数,x 位置在它们的定义域 和它们的定义域。这样应该很容易实现功能。

编辑:
quadratic function可能是您的 InFunction示例:

double InFunction( uint current, uint range )
{
return Math.Pow( ( current / range ) - 1, 2 );
}

通过将电流除以范围,您会得到一个介于 0 和 1 之间的值 - 这将确保结果也介于 0 和 1 之间(如您指定的那样)。

关于c# - 如何实现这个振荡功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1812010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com