3D vectors for astrodynamics and rendering
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add ocaml-vec3: shared 3D vector type

+87
+2
dune-project
··· 1 + (lang dune 3.21) 2 + (name vec3)
+4
lib/dune
··· 1 + (library 2 + (name vec3) 3 + (public_name vec3) 4 + (libraries fmt))
+31
lib/vec3.ml
··· 1 + type t = { x : float; y : float; z : float } 2 + 3 + let v x y z = { x; y; z } 4 + let zero = { x = 0.; y = 0.; z = 0. } 5 + let add a b = { x = a.x +. b.x; y = a.y +. b.y; z = a.z +. b.z } 6 + let sub a b = { x = a.x -. b.x; y = a.y -. b.y; z = a.z -. b.z } 7 + let scale s v = { x = s *. v.x; y = s *. v.y; z = s *. v.z } 8 + let dot a b = (a.x *. b.x) +. (a.y *. b.y) +. (a.z *. b.z) 9 + 10 + let cross a b = 11 + { 12 + x = (a.y *. b.z) -. (a.z *. b.y); 13 + y = (a.z *. b.x) -. (a.x *. b.z); 14 + z = (a.x *. b.y) -. (a.y *. b.x); 15 + } 16 + 17 + let length v = sqrt (dot v v) 18 + 19 + let normalize v = 20 + let l = length v in 21 + if l < 1e-12 then zero else scale (1. /. l) v 22 + 23 + let negate v = { x = -.v.x; y = -.v.y; z = -.v.z } 24 + let distance a b = length (sub a b) 25 + 26 + let equal ?(eps = 1e-12) a b = 27 + Float.abs (a.x -. b.x) <= eps 28 + && Float.abs (a.y -. b.y) <= eps 29 + && Float.abs (a.z -. b.z) <= eps 30 + 31 + let pp ppf v = Fmt.pf ppf "(%.4f, %.4f, %.4f)" v.x v.y v.z
+36
lib/vec3.mli
··· 1 + (** 3D vectors. 2 + 3 + Shared type for astrodynamics, coordinate transforms, and rendering. All 4 + packages (kepler, sgp4, globe, coordinate) use this type. *) 5 + 6 + type t = { x : float; y : float; z : float } 7 + (** A 3D vector. The interpretation (km, m/s, GL units) depends on context. *) 8 + 9 + val v : float -> float -> float -> t 10 + (** [v x y z] creates a vector. *) 11 + 12 + val zero : t 13 + (** The zero vector. *) 14 + 15 + val add : t -> t -> t 16 + val sub : t -> t -> t 17 + val scale : float -> t -> t 18 + val dot : t -> t -> float 19 + val cross : t -> t -> t 20 + val length : t -> float 21 + 22 + val normalize : t -> t 23 + (** [normalize v] is the unit vector in the direction of [v]. Returns [zero] if 24 + [length v < 1e-12]. *) 25 + 26 + val negate : t -> t 27 + (** [negate v] is [scale (-1.) v]. *) 28 + 29 + val distance : t -> t -> float 30 + (** [distance a b] is [length (sub a b)]. *) 31 + 32 + val equal : ?eps:float -> t -> t -> bool 33 + (** [equal ?eps a b] is [true] if all components differ by at most [eps] 34 + (default [1e-12]). *) 35 + 36 + val pp : t Fmt.t
+14
vec3.opam
··· 1 + opam-version: "2.0" 2 + synopsis: "3D vectors for astrodynamics and rendering" 3 + maintainer: ["Thomas Gazagnaire <thomas@gazagnaire.org>"] 4 + authors: ["Thomas Gazagnaire <thomas@gazagnaire.org>"] 5 + license: "ISC" 6 + depends: [ 7 + "ocaml" {>= "4.14"} 8 + "dune" {>= "3.0"} 9 + "fmt" 10 + ] 11 + build: [ 12 + ["dune" "subst"] {dev} 13 + ["dune" "build" "-p" name "-j" jobs] 14 + ]