Smooth movement up the atmosphere

I move through the atmosphere with Microsoft Virtual Earth 3D and I can go down smoothly, but I don’t know how math rises smoothly.

I go down like this:

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

This works by reducing the size of the jump, the closer I get closer to the ground (lower height). I need a solution that will do this, just the opposite, while keeping smaller jumps at a lower height.

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

+1
source share
4 answers

An even better solution would be to use a function, such as a 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();
        }
    }
}
+4

, ( ). , ; . - , Virtual Earth -, , -, Virtual Earth, , , . "" , 3D- , , .

, VSync, :

  • ( VSync).
  • , .

:

private int lastTime;

/:

if(lastTime == 0)
{
    lastTime = Environment.TickCount;
    return;
}

int curTime = Environment.TickCount; // store this baby.
int timeDiff = lastTime - curTime;

if(timeDiff == 0)
   return;

curAlt += (maxAlt - curAlt) * timeDiff / (150000); // TickCount reports
                                                   // time in Ticks
                                                   // (1000 ticks per second)

lastTime = curTime;

, DX SDK. Environment.TickCount 15 (, , timeDiff , ). DX SDK DxTimer ( ), .

, API.

+1

, , . maxAlt , .

curAlt += (maxAlt - curAlt) / 150

, , .

, . . .

epsilon = 0.1; // A small value that fits your needs

curAlt = startAlt;

while (curAlt > endAlt + epsilon)
{
   curAlt -= (curAlt - endAlt) / 150;
}

Iteration curAlt - = (curAlt - endAlt) / 150 will never reach the end in theory and, at best, with taxiing errors. Your code only works because you subtract one extra block of height per iteration. I'm not sure if this is a design or bug that prevents the bug. Adding an epsilon threshold breaks the loop in a more logical way.

0
source

Since you are using curAlt - = curAlt / 150 for rejection, why not use curAlt + = curAlt * 150 for climbing?

0
source

Source: https://habr.com/ru/post/1718345/


All Articles