Parameter MAKER.V3

type t

The type of 3D vectors.

val x : t -> float

x v is the x component of v.

  open Gg
  let v = V3.v 1.0 2.0 3.0
  let x_coord = V3.x v
  (* x_coord = 1.0 *)
val y : t -> float

y v is the y component of v.

  open Gg
  let v = V3.v 1.0 2.0 3.0
  let y_coord = V3.y v
  (* y_coord = 2.0 *)
val z : t -> float

z v is the z component of v.

  open Gg
  let v = V3.v 1.0 2.0 3.0
  let z_coord = V3.z v
  (* z_coord = 3.0 *)
val of_tuple : (float * float * float) -> t

of_tuple (x, y, z) creates a vector from a tuple.

  open Gg
  let v = V3.of_tuple (1.0, 2.0, 3.0)
  (* v = V3.v 1.0 2.0 3.0 *)
val to_tuple : t -> float * float * float

to_tuple v converts a vector to a tuple (x, y, z).

  open Gg
  let v = V3.v 1.0 2.0 3.0
  let (x, y, z) = V3.to_tuple v
  (* (1.0, 2.0, 3.0) *)
val add : t -> t -> t

add u v is the vector addition u + v.

  open Gg
  let u = V3.v 1.0 2.0 3.0
  let v = V3.v 4.0 5.0 6.0
  let sum = V3.add u v
  (* sum = V3.v 5.0 7.0 9.0 *)
val sub : t -> t -> t

sub u v is the vector subtraction u - v.

  open Gg
  let u = V3.v 4.0 5.0 6.0
  let v = V3.v 1.0 2.0 3.0
  let diff = V3.sub u v
  (* diff = V3.v 3.0 3.0 3.0 *)

mul u v is the component wise multiplication u * v.

val div : t -> t -> t

div u v is the component wise division u / v.

  open Gg
  let u = V3.v 6.0 8.0 10.0
  let v = V3.v 2.0 4.0 5.0
  let quotient = V3.div u v
  (* quotient = V3.v 3.0 2.0 2.0 *)
val norm : t -> float

norm v is the Euclidean norm (magnitude) of v.

Computes sqrt(x*x + y*y + z*z), the distance from the origin.

  open Gg
  let v = V3.v 3.0 4.0 0.0
  let magnitude = V3.norm v
  (* magnitude = 5.0 *)
  (* Unit vector has norm 1.0 *)
  let unit_x = V3.v 1.0 0.0 0.0
  let n = V3.norm unit_x
  (* n = 1.0 *)
val map : (float -> float) -> t -> t

map f v applies f to each component of v.

  open Gg
  let v = V3.v 1.0 2.0 3.0
  let doubled = V3.map (fun x -> x *. 2.0) v
  (* doubled = V3.v 2.0 4.0 6.0 *)
  (* Clamp all components to range [0, 1] *)
  let clamp01 x = max 0.0 (min 1.0 x)
  let v = V3.v 1.5 (-0.5) 0.7
  let clamped = V3.map clamp01 v
  (* clamped = V3.v 1.0 0.0 0.7 *)
val pp : Stdlib.Format.formatter -> t -> unit

pp ppf v prints a textual representation of v on ppf.

  open Gg
  let v = V3.v 1.0 2.0 3.0
  let () = Format.printf "Point: %a@." V3.pp v
  (* Output: Point: (1 2 3) *)

compare u v is Stdlib.compare u v.