我如何更改方程以将线上的数字调制为在正弦曲线上调制的数字?
我正在尝试调整我在 Android 上构建的 Java 应用程序中的 alpha 值。现在它是这样的:
if (goingUp) {
newAlpha = oldAlpha + rateOfChange;
if (newAlpha > maxAlpha) {
newAlpha = maxAlpha;
goingUp = false;
}
} else {
newAlpha = oldAlpha - rateOfChange;
if (newAlpha < minAlpha) {
newAlpha = minAlpha;
goingUp = true;
}
}
其中 rateOfChange 是一个不能大于 maxAlpha 的任意 int。该方程计算线程中的每个时钟周期并且与时间无关。
有没有办法仅使用给定的变量 + Math.PI 和其他数学元素(我假设 Math.Sine 将在那里)来使 newAlpha 成为正弦上的数字?
我认为 min 和 max 是波的放大器,rateOfChange 是正弦函数的乘积,我只是不明白它们是如何结合在一起的。
I'm trying to modulate an alpha value in a Java application I'm building on Android. Right now it goes like this:
if (goingUp) {
newAlpha = oldAlpha + rateOfChange;
if (newAlpha > maxAlpha) {
newAlpha = maxAlpha;
goingUp = false;
}
} else {
newAlpha = oldAlpha - rateOfChange;
if (newAlpha < minAlpha) {
newAlpha = minAlpha;
goingUp = true;
}
}
Where rateOfChange is an arbitrary int that cannot be greater than maxAlpha. The equation is evaluate every tick in a thread and is independent of time.
Is there a way using only the variables given + Math.PI and other Math elements (I'm assuming Math.Sine will be in there) to get newAlpha to be a number on a Sine?
I'm thinking min and max would be the amp of the wave and rateOfChange would be a product of the Sine function, I just can't figure out how it all goes together.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的方程将如下所示:
y 是时间 t 时的垂直位置,A 是幅度,f 是频率,t 是时间(或 Android 时钟的滴答声)。
Your equation will look like this:
y is vertical position at time t, A is the amplitude, f is the frequency, and t is the time (or ticks of your Android clock).
你为什么不考虑这个呢?
...在类定义的顶部,包括:-
...以及在您的函数中,在分配给 newAlpha 之后,
如果您希望 newAlpha 作为 sin() 函数在 [-1,1] 范围内是
OR
...在你的函数中,在分配给 newAlpha 之后,
如果你希望 newAlpha 在 [-1,1] 范围内,因为 sin() 函数是
我不确定你的 newAlpha 是什么数据类型,但是我假设它不会影响这个表达式的答案 - 就像 newAlpha 是 double 类型一样。
通常,将模数应用于您拥有的任何表达式,即获得一定范围内的数字的方法。 expr%N 结果是 [0,N-1] 范围内的数字。
希望这有帮助。
Why don't you consider this?
...at the top of your class definition, include:-
...and within your function, after the assignment to newAlpha,
if you would like newAlpha to be in the range [-1,1] as the sin() function is
OR
...within your function, after the assignment to newAlpha,
if you would like newAlpha to be in the range [-1,1] as the sin() function is
I'm not sure what datatype your newAlpha is, but I'm going to assume it will not affect the answer for this expression - like newAlpha is of type double.
It is generally the way to get a number within a certain range that you apply modulus to whatever expression you have ie. expr%N results in a number in range [0,N-1].
Hope this helps.
根据达菲莫的一般方程,我必须一直追溯到我的 TI-83 日子(字面意思是,将应用程序放在我的手机上)。但我能够将所有部分放在一起,所以它最终看起来像这样:
FMI:http://en .wikipedia.org/wiki/Sine_wave
Based on duffymo's general equation I had to go all the way back to my TI-83 days (literally, put the app on my phone). But I was able to put all the pieces together so it ended up looking like this:
FMI: http://en.wikipedia.org/wiki/Sine_wave