ecef_to_geodetic
Convert Earth-Centered, Earth-Fixed (ECEF) coordinates to geodetic latitude, longitude, and altitude for aviation and aerospace applications.
Instructions
Convert ECEF coordinates to geodetic (lat/lon/alt) coordinates.
Args: x_m: X coordinate in meters y_m: Y coordinate in meters z_m: Z coordinate in meters
Returns: JSON string with geodetic coordinates
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| x_m | Yes | ||
| y_m | Yes | ||
| z_m | Yes |
Implementation Reference
- aerospace_mcp/tools/frames.py:83-121 (handler)MCP tool handler: imports core function from integrations, executes conversion, formats input/output as JSON, handles errors.def ecef_to_geodetic(x_m: float, y_m: float, z_m: float) -> str: """Convert ECEF coordinates to geodetic (lat/lon/alt) coordinates. Args: x_m: X coordinate in meters y_m: Y coordinate in meters z_m: Z coordinate in meters Returns: JSON string with geodetic coordinates """ try: from ..integrations.frames import ecef_to_geodetic as _ecef_to_geodetic result = _ecef_to_geodetic(x_m, y_m, z_m) return json.dumps( { "input": {"x_m": x_m, "y_m": y_m, "z_m": z_m}, "output": { "latitude_deg": result["latitude_deg"], "longitude_deg": result["longitude_deg"], "altitude_m": result["altitude_m"], }, "reference_frame": "WGS84 Geodetic", "units": { "latitude": "degrees", "longitude": "degrees", "altitude": "meters", }, }, indent=2, ) except ImportError: return "Coordinate conversion not available - geodetic module required" except Exception as e: logger.error(f"ECEF to geodetic error: {str(e)}", exc_info=True) return f"ECEF to geodetic error: {str(e)}"
- Pydantic model for output geodetic coordinates (lat, lon, alt), used by the core conversion function.class GeodeticPoint(BaseModel): """Geodetic coordinates.""" latitude_deg: float = Field(..., description="Latitude in degrees") longitude_deg: float = Field(..., description="Longitude in degrees") altitude_m: float = Field(..., description="Height above ellipsoid (m)")
- aerospace_mcp/fastmcp_server.py:97-97 (registration)FastMCP registration of the ecef_to_geodetic tool function.mcp.tool(ecef_to_geodetic)
- Core helper: iterative numerical algorithm for ECEF to geodetic conversion using WGS84 ellipsoid parameters.def _manual_ecef_to_geodetic( x: float, y: float, z: float ) -> tuple[float, float, float]: """ Convert ECEF to geodetic coordinates using iterative method. Returns (lat_deg, lon_deg, alt_m). """ # Longitude lon_rad = math.atan2(y, x) # Distance from z-axis p = math.sqrt(x**2 + y**2) # Initial guess for latitude lat_rad = math.atan2(z, p * (1.0 - EARTH_E2)) # Iterative solution for latitude and altitude for _ in range(10): # Usually converges in 2-3 iterations sin_lat = math.sin(lat_rad) N = EARTH_A / math.sqrt(1.0 - EARTH_E2 * sin_lat**2) alt = p / math.cos(lat_rad) - N lat_rad_new = math.atan2(z, p * (1.0 - EARTH_E2 * N / (N + alt))) if abs(lat_rad_new - lat_rad) < 1e-12: break lat_rad = lat_rad_new return math.degrees(lat_rad), math.degrees(lon_rad), alt
- Integration wrapper: calls manual converter, validates with Pydantic model for structured output.def ecef_to_geodetic(x: float, y: float, z: float) -> GeodeticPoint: """ Convert ECEF coordinates to geodetic (WGS84). Args: x, y, z: ECEF coordinates in meters Returns: GeodeticPoint with latitude, longitude, altitude """ lat, lon, alt = _manual_ecef_to_geodetic(x, y, z) return GeodeticPoint(latitude_deg=lat, longitude_deg=lon, altitude_m=alt)