Computing midpoint of two GeodeticPoints

I am trying to write a function that computes the midpoint of two geodetic coordinates (lat, lon, alt). It returns the correct latitude & longitude currently but the altitude is off.


    public static GeodeticPoint computeMidpoint(GeodeticPoint gp1, GeodeticPoint gp2) {
        // For reference (extracted from external class)
        // OrekitConfig.EARTH_FRAME = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
        // OrekitConfig.EARTH = new OneAxisEllipsoid(
        //         Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
        //         Constants.WGS84_EARTH_FLATTENING,
        //         EARTH_FRAME
        // );

        // Convert geodetic coordinates to Cartesian
        Vector3D c1 = OrekitConfig.EARTH.transform(gp1);
        Vector3D c2 = OrekitConfig.EARTH.transform(gp2);

        Vector3D midpoint = c1.add(c2).scalarMultiply(0.5);

        AbsoluteDate date = new AbsoluteDate(
        // Convert Cartesian back to geodetic
        return OrekitConfig.EARTH.transform(

In the caller, each GeodeticPoint gp comes from a SpacecraftState s, i.e.,
gp = OrekitConfig.EARTH.transform(s.getPosition(), s.getFrame(), s.getDate());

Test case

    void testComputeMidpoint() {
        GeodeticPoint gp1 = new GeodeticPoint(Math.toRadians(40.730610), Math.toRadians(-73.935242), 31.09); // New York, NY
        GeodeticPoint gp2 = new GeodeticPoint(Math.toRadians(37.773972), Math.toRadians(-122.431297), 20.11); // San Francisco, CA

        GeodeticPoint midpoint = computeMidpoint(gp1, gp2); // Ericson, NE

            () -> assertEquals(41.78, Math.toDegrees(midpoint.getLatitude()), 0.3),
            () -> assertEquals(-98.68, Math.toDegrees(midpoint.getLongitude()), 0.3),
            () -> assertEquals(611, midpoint.getAltitude(), 0.1)

Expected: { lat=41.78, lon=-98.68, altitude=611}
Actual: { lat=41.78, lon=-98.68, altitude=-333383.471179875}

Any insights appreciated. Thank you.

You are computing a straight line in Cartesian through Earth surface, here, so it is expected the midpoint is at a very low altitude.

1 Like

I see. I would like the line follow the curvature of the Earth before grabbing it’s midpoint; does Orekit have a way of modelling that?

Thank you for your help.

Yes, it is possible, even for points very far away from each other, but you have to make sure this suits your needs.
You can look at the LoxodromeArc class and its calculatePointAlongArc method. I am not sure how it handles altitude, though so you may end up defining the loxodrome arc using two points at zero altitude, compute the intermediate point also at zero altitude, and then interpolate the altitude between the two endpoints altitudes.

1 Like