Search code examples
javagoogle-project-tango

Calculate distance from TangoPoseData


My Project Tango device has recorded two Java TangoPoseData observations. How can I calculate distance, in meters, between those two observations?


Solution

  • From the Coordinate Pair Frames Documentation:

    For all coordinate frame pairs, the unit of measurement is meters.

    Also...

    Project Tango uses a right-handed, local-level frame for the START_OF_SERVICE and AREA_DESCRIPTION coordinate frames. This convention sets the Z-axis aligned with gravity, with Z+ pointed upwards, and the X-Y plane is perpendicular to gravity that is locally level with the ground plane.

    So the coordinates can be used with standard libraries like JTS Topology Suite for coordinates using START_OF_SERVICE and AREA_DESCRIPTION coordinate frames.

    public static Coordinate coordinate(TangoPoseData pose){
    
        return new Coordinate(pose.translation[TangoPoseData.INDEX_TRANSLATION_X],
                    pose.translation[TangoPoseData.INDEX_TRANSLATION_Y],
                    pose.translation[TangoPoseData.INDEX_TRANSLATION_Z]);
    }
    

    Coordinates provide a distance method:

    double distanceInMeters = coordinate(pose1).distance(coordinate(pose2));