# Getting NaN converting ECI to Geodetic

Hello, please forgive my ignorance, I am new to Orbital Mechanics. While trying to convert the following ECEF position to Geodetic, I am getting NaN as my resulting latitude and am not sure how to proceed.

Here is my input vector:

Vector3D nanVector = new Vector3D(-5585.64609241433, -1101.1029255805272, -3935.9879738301124);

And my time:

Instant time = Instant.ofEpochMilli(1683508165764L);

I first convert the Instant to an AbsoluteDate (2023-05-08T01:09:25.764Z) then call this method:

``````    /**
* Transforms an ECI position to a Topocentric position.
*
* @param date     Observation date
* @return GeodeticPoint
*/
GeodeticPoint eciToGeodetic(AbsoluteDate date, Vector3D position) {
// Define the Earth ellipsoid (WGS84 in this case)
OneAxisEllipsoid earth = new OneAxisEllipsoid(
Constants.WGS84_EARTH_FLATTENING,
FramesFactory.getITRF(IERSConventions.IERS_2010, true)
);
// Extract Geodetic coordinates
return earth.transform(position, earth.getBodyFrame(), date);
}
``````

The returned GeodeticPoint looks like this:
{lat: NaN deg, lon: -168.8482242084 deg, alt: -6,359,220.702133572}

My thinking is that I might not have my “earth” variable setup incorrectly for the incoming data. Any thoughts or pointers would be much appreciated.

sg

Hello @gormanst!

I tried to replicate this issue but I was able to get an answer for the latitude. I can’t see what you may be doing differently.

I would like to point out that the `Vector3D` position values should be expressed in meters. A general rule of thumb for Orekit is that all values are in S.I. units (meters, radians, kg, sec). The values you provide are therefore several kilometers per axis, well within the earth’s body. Still, the attached code below did not complain.

I have attached a passing test class that shows that your inputs and code should still work in Orekit `12.0`. I assume you use `12.0` because you are attempting to use an `Instant` for time, and the `AbsoluteDate` constructor that consumes an `Instant` was just added in 12.0.

I look forward to the expert’s advice as well!
TestECEFToGeodetic.java (2.5 KB)

Manny, thank you so much for your efforts.

I took your test and with what seems like a minor change, plugged it into my testing code and it fails for the same reason mentioned in my original post. My “minor” change was where you call earth.transform, you pass in time like this:

new AbsoluteDate(time, TimeScalesFactory.getUTC())

My compiler complained, telling me there was no constructor for AbsoluteDate that takes an Instant and a TimeScale. This makes me wonder …

implementation group: ‘org.orekit’, name: ‘orekit’, version: ‘11.3.3’

I upgraded to 12.0 and it worked! … no more NaN.

Could that even be possible? I trust the experts will show me the error of my ways.

Thank you again for such excellent help.
sg

1 Like

I was able to replicate the issue in `11.3.3`. Then, I did some investigation in the code of `transform` method between `11.3.3` and `12.0`. In `12.0`, there are attempts to make the `transform` method more robust by increasing the amount of maximum iterations from `10` to `1000`. In `12.0`, if the code still does not converge after 1000 iterations, there is a best effort approach and the best approximation of latitude is returned, so that NaN is not returned (quoted from the source documentation).

There is also an issue opened on this topic that got resolved with 12.0, so I feel that upgrading Orekit to 12.0 will resolve such issues!