Getting NaN values out of a function. Need help to solve the problem.,Getting NaN values out of a function, and I do not understand why.
Made a orbit script, it uses degrees / radians to calculate the orbiting bodys next position based on its speed. From what i can tell the function works flawlessly for 1 second at the most then outputs a NaN value. This is a reversed version of a elliptical arch length equation. (to find angle A insted of arch length)
double x = Math.Abs(Math.Sqrt(Math.Acos((Math.Pow(
Math.Sqrt((_Orbit.SemiMajorAxis - b) / _Orbit.SemiMajorAxis), (v + _Orbit.SemiMajorAxis *
Math.Log((Distance * (_Orbit.OrbitPosition * (Math.PI / 180)) * Math.Cos(_Orbit.OrbitPosition * (Math.PI / 180))) / _Orbit.SemiMajorAxis, Math.Sqrt((_Orbit.SemiMajorAxis - b) / _Orbit.SemiMajorAxis)))
/ _Orbit.SemiMajorAxis)) * _Orbit.SemiMajorAxis) / Distance));
This function takes in _OrbitPosition (always between 0 and 360) and v (velocity, constantly changeing always above 0)
double v = Math.Sqrt((mass * 0.00000000006674f) * ((2 / Distance) - (1 / _Orbit.SemiMajorAxis)));
Distance, SemiMajorAxsis, and b (semiminoraxsis) are always grater then 0;
Like I said in the second it works, the orbiting bodys move the distance the should move in that second, but it will always seam to break with a NaN value. I know its this part of the code becuase this dose not happen if i change double x to somthing like:
double x =(((c / 360) * _Orbit.OrbitPosition + (v*Time.deltaTime)) / c) * 360;
Any help would be much appreciated!!!
Your answer
![](https://koobas.hobune.stream/wayback/20220612183702im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to make an object orbit around another object? 0 Answers
Position an object at a specific point in an orbit 0 Answers
Orbit On Rails 1 Answer
Orbit Camera with mouse drag, locked at x rotation? 0 Answers
Move a object around another object 0 Answers