Class GeoCoordinateConverter
Helper class that converts Unity world-space positions to WGS84 geodetic coordinates (latitude, longitude, ellipsoid height) for geo-referenced export of actor trajectories.
public class GeoCoordinateConverter
Inheritance
Examples
Calibrate a Unity-world origin by converting a known real-world GPS anchor point to
ECEF, then subtract actor ECEF coordinates from the origin to get a scene-relative
offset. A round-trip through BLH2XYZ then XYZ2BLH recovers the
original WGS84 values (within floating-point precision):
// 1. Convert the study-site anchor (Honda R&D campus gate) from WGS84 to ECEF.
double anchorLat = 35.7745, anchorLon = 139.6233, anchorAlt = 50.0;
var (ox, oy, oz) = GeoCoordinateConverter.BLH2XYZ(anchorLat, anchorLon, anchorAlt);
// 2. Convert an actor's current GPS position to ECEF.
double actorLat = 35.7750, actorLon = 139.6240, actorAlt = 50.5;
var (ax, ay, az) = GeoCoordinateConverter.BLH2XYZ(actorLat, actorLon, actorAlt);
// 3. The ECEF delta can be mapped to Unity's local axes for geo-referenced export.
double dx = ax - ox, dy = ay - oy, dz = az - oz;
// 4. Round-trip back to WGS84 to verify precision (should equal actorLat/Lon/Alt).
var (la, lo, el) = GeoCoordinateConverter.XYZ2BLH(ax, ay, az);
// la ≈ 35.7750, lo ≈ 139.6240, el ≈ 50.5
Remarks
When the virtual driving environment is calibrated to a real-world road layout, exporting positions in WGS84 allows trajectories to be overlaid on mapping tools (e.g., QGIS or Google Maps) for post-hoc spatial analysis without converting from a proprietary coordinate system.
Only the minimum conversions required for the study are implemented to keep the class simple. The calculation follows the World Geodetic System 1984 (WGS84) ellipsoid parameters and the method from Tobita (Japan Surveying Association).
Methods
BLH2XYZ(double, double, double)
Method to convert from latitude/longitude (WGS84) to Cartesian coordinates (ECEF).
public static (double x, double y, double z) BLH2XYZ(double la, double lo, double el)
Parameters
| Name | Type | Description |
|---|---|---|
la | double | Latitude |
lo | double | longitude |
el | double | ellipsoid height |
Returns
(``double x, double y, double z) — XYZ in Cartesian coordinates. +Z is north pole, +X is meridian, +Y is east longitude
XYZ2BLH(double, double, double)
Method to convert from Cartesian coordinates (ECEF) to latitude/longitude (WGS84).
public static (double la, double lo, double el) XYZ2BLH(double x, double y, double z)
Parameters
| Name | Type | Description |
|---|---|---|
x | double | X |
y | double | Y |
z | double | Z |
Returns
(``double la, double lo, double el``) — Latitude, longitude, and ellipsoid height