Trajectories.Trajectory.FindOrbitBodyIntersection C# (CSharp) Method

FindOrbitBodyIntersection() private method

private FindOrbitBodyIntersection ( Orbit orbit, double startTime, double endTime, double bodyAltitude ) : double
orbit Orbit
startTime double
endTime double
bodyAltitude double
return double
		private double FindOrbitBodyIntersection(Orbit orbit, double startTime, double endTime, double bodyAltitude)
		{
			// binary search of entry time in atmosphere
			// I guess an analytic solution could be found, but I'm too lazy to search it

			double from = startTime;
			double to = endTime;

			int loopCount = 0;
			while (to - from > 0.1)
			{
				++loopCount;
				if (loopCount > 1000)
				{
					UnityEngine.Debug.Log("WARNING: infinite loop? (Trajectories.Trajectory.AddPatch, atmosphere limit search)");
					++errorCount_;
					break;
				}
				double middle = (from + to) * 0.5;
				if (orbit.getRelativePositionAtUT(middle).magnitude < bodyAltitude)
				{
					to = middle;
				}
				else
				{
					from = middle;
				}
			}

			return to;
		}