3D vectors for astrodynamics and rendering
README.md

vec3 #

An orbit propagator produces positions and velocities, a coordinate transform
rotates them, and a globe renderer draws them. If each library defines its own
vector type, every boundary between them needs a conversion. vec3 is the
small 3D vector type they share: the kepler, sgp4, globe and
coordinate packages all exchange Vec3.t values. It is a record of three
floats, and the unit of the components (kilometres, metres per second, GL
units) depends on the caller.

Installation #

Install with opam:

$ opam install vec3

If opam cannot find the package, it may not yet be released in the public
opam-repository. Add the overlay repository, then install it:

$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install vec3

Usage #

open Vec3
let a = v 1.0 2.0 3.0
let b = v 4.0 5.0 6.0
let c = add a b
let d = cross a b
let len = length c
let unit = normalize c
let () = Fmt.pr "%a cross %a (length: %f)@." pp unit pp d len

API #

  • v x y z builds a vector and zero is the zero vector.
  • add, sub, scale and negate are the arithmetic.
  • dot and cross are the scalar and vector products.
  • length is the Euclidean norm and distance the norm of the difference.
  • normalize is the unit vector in the same direction, or zero when the
    length is below 1e-12.
  • equal ?eps compares component by component within eps (defaults to
    1e-12).
  • pp formats a vector to four decimal places.

Licence #

ISC