Skip to content
Andrew Voirol
Monday, August 31, 2026terragemini-build

MGRS/UTM geodetic conversion and 3D screen-to-sphere raycasting

ReactTypeScriptVisualization

TerraGemini integrates a full WGS84 ellipsoid geodetic conversion engine with real-time screen-to-sphere raycasting and 3D target lock tracking.

1. Screen-to-Sphere Raycasting

When the user clicks or hovers at screen coordinate (xs,ys)(x_s, y_s)(xs​,ys​), the coordinate is unprojected into spherical unit space relative to center (cx,cy)(c_x, c_y)(cx​,cy​) and scale SSS:

rx=xs−cxS,ry=−ys−cySr_x = \frac{x_s - c_x}{S}, \quad r_y = -\frac{y_s - c_y}{S}rx​=Sxs​−cx​​,ry​=−Sys​−cy​​

If rx2+ry2≤1.0r_x^2 + r_y^2 \le 1.0rx2​+ry2​≤1.0, front-hemisphere depth rz=1.0−(rx2+ry2)r_z = \sqrt{1.0 - (r_x^2 + r_y^2)}rz​=1.0−(rx2​+ry2​)​ is computed and multiplied by the inverse camera rotation matrix R−1=Ry(−θy)Rx(−θx)\mathbf{R}^{-1} = R_y(-\theta_y) R_x(-\theta_x)R−1=Ry​(−θy​)Rx​(−θx​) to extract geodetic latitude ϕ=arcsin⁡(py)\phi = \arcsin(p_y)ϕ=arcsin(py​) and longitude λ=atan2⁡(px,pz)\lambda = \operatorname{atan2}(p_x, p_z)λ=atan2(px​,pz​).

2. WGS84 to MGRS (1-Meter Precision)

The geodetic coordinates are processed through a UTM projection engine (calculating meridian arc distance MMM and 5th-order series expansions) and mapped to the Military Grid Reference System (MGRS):

  • Derives the 6° UTM zone and 8° latitude band.
  • Identifies the 100,000m grid square using DoD/NGA row letter offset sets.
  • Produces 1-meter precision coordinates (e.g. 18T WL 83959 07350).

The locked target maintains dynamic 3D-to-2D screen tracking, rendering animated radar rings, occlusion culling on back-face rotation, and dynamic SVG leader lines anchored to the telemetry HUD.

← Previous

3x3 Sobel normal gradient convolution for procedural coastlines

Next →

Continuous unfurl engine: Pythagorean limb departure and dynamic horizon clipping


Andrew Voirol

Builder, hacker, shipper. Currently leaving localhost.

Navigate

WorkThreadsBuilder's LogAboutContactRSS Feed

Connect

X / TwitterGitHubLinkedIn

© 2026 Andrew Voirol·Back to top ↑
✦Just one prompt away from figuring it all out.