平滑的运动来提升穿越大气层大气层、平滑

2023-09-07 10:23:16 作者:渡舟

我通过与微软的Virtual Earth 3D和我的气氛能够顺利下降感动,但我不知道数学顺利提升。

I'm moving through the atmosphere with Microsoft Virtual Earth 3D and I can descend smoothly, but I don't know the math to ascend smoothly.

我降是这样的:

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

该作品通过减少跳越接近我到达地球(低海拔)的大小。我需要一个会做类似的,只是在背面,同时仍保持较小的跳跃在海拔较低的解决方案。

This works by decreasing the size of the jump the closer I get to the earth (lower altitude). I need a solution that would do similar, just in reverse, while still keeping the smaller jumps at the lower altitude.

我怎样才能做到这一点?或者是我在做什么不能接受的,应该做的不同(与对数说)?

How can I do this? Or is what I am doing unacceptable and should be done differently (say with logarithms)?

推荐答案

这是更好的解决方案可能是使用一个函数像的物流功能。

An even better solution might be to use a function like the 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;
}

由于目前的高度被明确计算你不必依靠迭代计算引入各种precision相关型号的错误。

Because the current altitude is explicitly calculated you do not have to rely on a iterative calculation introducing all sorts of precision releated errors.

请参阅样本$ C $下如何调整功能形状。

See the sample code for how to tune the function shape.

下面是一个显示功能的示例控制台应用程序。您可以打了一下的参数,以获得行为的一种感觉。

Here is a sample console application that displays the function. You can play a bit with the parameters to get a feeling for the behavior.

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();
        }
    }
}
 
精彩推荐
图片推荐