startmacro n:lat1[44.0] n:lon1[33.0] n:lat2[45.0] n:lon2[34.0]

  call geoToCartesian lat1 lon1 cart1 ! Transform point 1 from GEO to CART

  call geoToCartesian lat2 lon2 cart2 ! Transform point 2 from GEO to CART

  calc dist cart1 cart2 - mag         ! Compute the miss distance

  say "Miss distance is ^dist meters"
  
endmacro

!**************************************************************************************************!
procedure geoToCartesian n:lat n:lon U:cartRes

  new nxm.sys.lib.Position pos          ! Creates a postion object. Could be done once at top
  invoke stat pos.setGeo(0,^lat,^lon)   ! Sets the position in a GEODETIC coordinate system
  invoke stat pos.geo2car()             ! Transforms position to CARTESIAN for miss calculation

  res ^cartRes (pos.x,pos.y,pos.z)      ! Returns the result as a vector in given result name

return
