gpt4 book ai didi

c# - 流畅的运动上升穿过大气层

转载 作者:太空宇宙 更新时间:2023-11-03 20:46:24 25 4
gpt4 key购买 nike

我正在使用 Microsoft Virtual Earth 3D 穿越大气层,我可以平稳下降,但我不知道如何顺利​​上升。

我是这样下降的:

for(int curAlt = startAlt; curAlt < endAlt; curAlt--){
//do something
curAlt -= curAlt/150
}

当我离地球越近(海拔越低)时,跳跃的幅度就越小。我需要一个类似的解决方案,只是相反,同时仍将较小的跳跃保持在较低的高度。

我该怎么做?或者我正在做的事情是 Not Acceptable ,应该以不同的方式来做(比如用对数)?

最佳答案

更好的解决方案可能是使用类似 Logistic function 的函数.

Double minAlt = 0.0;
Double maxAlt = 500000.0;

Int32 numberSteps = 1000;

Double boundary = +6.0;

for (Int32 step = 0; step < numberSteps; step++)
{
Double t = -boundary + 2.0 * boundary * step / (numberSteps - 1);
Double correction = 1.0 / (1.0 + Math.Exp(Math.Abs(boundary)));
Double value = 1.0 / (1.0 + Math.Exp(-t));
Double correctedValue = (value - correction) / (1.0 - 2.0 * correction);
Double curAlt = correctedValue * (maxAlt - minAlt) + minAlt;
}

因为当前高度是明确计算的,所以您不必依赖引入各种精度相关错误的迭代计算。

有关如何调整函数形状的示例代码。


这是一个显示函数的示例控制台应用程序。您可以稍微调整一下参数以感受一下行为。

using System;

namespace LogisticFunction
{
class Program
{
static void Main(string[] args)
{
Double minAlt = 5.0;
Double maxAlt = 95.0;

Int32 numberSteps = 60;

// Keep maxAlt and numberSteps small if you don't want a giant console window.
Console.SetWindowSize((Int32)maxAlt + 12, numberSteps + 1);

// Positive values produce ascending functions.
// Negative values produce descending functions.
// Values with smaller magnitude produce more linear functions.
// Values with larger magnitude produce more step like functions.
// Zero causes an error.
// Try for example +1.0, +6.0, +20.0 and -1.0, -6.0, -20.0
Double boundary = +6.0;

for (Int32 step = 0; step < numberSteps; step++)
{
Double t = -boundary + 2.0 * boundary * step / (numberSteps - 1);
Double correction = 1.0 / (1.0 + Math.Exp(Math.Abs(boundary)));
Double value = 1.0 / (1.0 + Math.Exp(-t));
Double correctedValue = (value - correction) / (1.0 - 2.0 * correction);
Double curAlt = correctedValue * (maxAlt - minAlt) + minAlt;

Console.WriteLine(String.Format("{0, 10:N4} {1}", curAlt, new String('#', (Int32)Math.Round(curAlt))));
}

Console.ReadLine();
}
}
}

关于c# - 流畅的运动上升穿过大气层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/706952/

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