みんな。ここで説明されているように、複数のデータ値間の補間を実装するために (間隔を除いて) Python にいくぶん似た構文を持つプログラムである Game Maker を使用しています。原点が x = 0、末尾が x = 100 で、各データ値の間隔が等しい散布図を想像してください。x 位置は一定ですが、y 位置は任意の値を持つことができます。各データ ポイント間で線が接続されている場合、理想的には、スクリプトは特定の x 位置の y を見つけることができます。これが私の元の実装でした:
// This is executed once.
nums = 3; // the number of values to interpolate between
t = 0; // the position along the "scatterplot" of values
// Values may be decimals with any sign. There should be values >= nums.
ind[0] = 100;
ind[1] = 0;
ind[2] = 100;
//This is executed each step.
intervals = 100 / (nums - 1);
index = round(percent / intervals);
if percent != 0 {newpercent= (intervals / (percent - index)) / 100;}
else {newpercent = 0;}
newval = ind[index] * (1 - newpercent) + ind[index + 1] * newpercent;
これは、指定された x 位置を囲む 2 つのポイントを見つけた後に lerp() を使用して、2 つの値の間の補間を返す必要がありましたが、そうではなかったので、私の質問は次のとおり
です。 前もって感謝します。
編集:完成した作業コードは次のとおりです。
// This is executed once.
nums = 3; // the number of values to interpolate between
t = 0; // the position along the "scatterplot" of values
// Values may be decimals with any sign. There should be values >= nums.
ind[0] = 100;
ind[1] = 0;
ind[2] = 100;
// This is executed each step; setting the result to 'alpha'.
if (nums > 1) {
if (t != 1) {
_temp1 = 1 / (nums - 1);
_temp2 = floor(t / _temp1);
_temp3 = (t - (_temp1 * _temp2)) * (nums - 1);
alpha = ind[_temp2] + _temp3 * (ind[_temp2 + 1] - ind[_temp2]);
}
else {
alpha = ind[nums - 1];
}
}