編輯
按照您的評論,這裏是提供各種有用的可選參數的正弦曲線分佈的函數。
private static double SinDistribution(
double value,
double lowToHighMeanPoint = 0.0,
double length = 10.0,
double low = -1.0,
double high = 1.0)
{
var amplitude = (high - low)/2;
var mean = low + amplitude;
return mean + (amplitude * Math.Sin(
(((value - lowToHighMeanPoint) % length)/length) * 2 * Math.PI));
}
您可以像這樣使用它來獲得您想要的結果。
for (double i = 0.0; i < 24.0; i++)
{
Console.WriteLine("{0}: {1}", i, SinDistribution(i, 6.5, 24.0, -6.0, 35.0));
}
這顯然折扣環境因素,並假設一天是春分,但我認爲它回答了這個問題。
所以,
double EstimatedTemperature(double hour, double[] distribution)
{
var low = Math.Floor(hour);
var lowIndex = (int)low;
var highIndex = (int)Math.Ceiling(hour);
if (highIndex > distribution.Count - 1)
{
highIndex = 0;
}
if (lowIndex < 0)
{
lowIndex = distribution.Count - 1;
}
var lowValue = distribution.ElementAt(lowIndex);
var highValue = distribution.ElementAt(highIndex);
return lowValue + ((hour - low) * (highValue - lowValue));
}
假設在發佈包的每個點之間的相當簡單的線性過渡。如果小時映射到分佈中不存在的元素,則會得到錯誤的結果。
寫類將有24個元素,其中你將有每小時值的數組。添加一個需要浮動的函數。取整數和它的分數,並且(取決於你需要的分佈)選擇正確的溫度。我沒有看到任何複雜的;) –
不應該19.76回到9.25左右? –
@ElRonnoco - 是的,我給了一個(非常差)的近似值。 – verenion