【发布时间】:2012-04-10 12:01:36
【问题描述】:
我一直试图找到一个我不久前在 LPC 中使用(未编写)的方便方法的 Javascript 版本,它被称为 dimval(),它采用以下形式:
NAME
dimval() - returns values with a reduced increase in output
as input values grow larger.
SYNOPSIS
float dimval(float input, float max_input, float max_output,
float min_input, float min_output, float rate);
DESCRIPTION
Returns (as a float) a value between min_output and max_output,
with values increasing at a reduced rate as they move from
min_input toward max_output.
Input is the input value.
Max_input is the maximum acceptable input. Any higher input
value will be capped to this.
Max_output is the maximum value returned.
Min_input is the (optional) minimum input. Default is zero.
Min_output is the (optional) minimum output. Default is zero.
Rate determines how quickly the cost increases to achieve
greater return values. Higher numbers are faster, lower numbers
are slower.
我read this article,但它似乎没有捕捉到我想要的东西(一开始看起来更简单)。我也 read this SO question 和...好吧,我认为这可以工作...但说实话,数学超出了我的范围。我了解上面的描述以及参数如何协同工作以产生我想要的结果。
如果有人可以在 Javascript 中提供具有上述限制的方法,我将不胜感激。
干杯!
编辑:原始方法的示例输出。
- eval return dimval(5.0, 100.0, 100.0, 0.0, 0.0, 1.0) => 22.360680
- eval return dimval(10.0, 100.0, 100.0, 0.0, 0.0, 1.0) => 31.622776
eval return dimval(50.0, 100.0, 100.0, 0.0, 0.0, 1.0) => 70.710678
eval return dimval(10.0, 100.0, 100.0, 0.0, 0.0, 2.0) => 15.811388
eval return dimval(10.0, 100.0, 100.0, 0.0, 0.0, 10.0) => 3.162278
eval return dimval(200.0, 100.0, 100.0, 0.0, 0.0, 10.0) => 10.000000
eval return dimval(200.0, 100.0, 100.0, 0.0, 0.0, 1.0) => 100.000000
eval return dimval(1.0, 100.0, 100.0, 10.0, 0.0, 10.0) => 0.000000
如果您希望我运行更多示例,请告诉我。
【问题讨论】:
-
你知道,我什至不确定这个问题的标题是否准确,我是根据我曾经使用的方法的名称,以及到目前为止所做的研究。如有错误请指正。
-
“他们从 min_input 向 max_output 移动”是真的吗?不是从
min_input到max_input? -
我将在几秒钟内使用一些示例值进行编辑,实际上我仍然可以运行旧的 LPC 方法,但没有代码。
标签: javascript math calculus