Module OgamlMath.Vector3i

Operations on immutable vectors of 3 ints

This module defines the vector3i type and various operations on it.

exception Vector3i_exception of string
Raised when an error occurs (usually a division by zero)

Vector operations

type t = {x : int; y : int; z : int}
Type of immutable vectors of 3 ints

Record fields

x : int
y : int
z : int
val make : int -> int -> int -> t
Fast way to create a vector
val zero : t
Zero vector
val unit_x : t
Unit x vector
val unit_y : t
Unit y vector
val unit_z : t
Unit z vector
val add : t -> t -> t
Adds two vectors together
val sub : t -> t -> t
sub u v computes the vector u - v
val prop : int -> t -> t
Multiplies a vector by a scalar
val div : int -> t -> t
Divides a vector by a scalar. Raises Vector3i_exception if the scalar is zero.
val pointwise_product : t -> t -> t
Computes the pointwise product of two vectors.
val pointwise_div : t -> t -> t
Computes the pointwise division of two vectors.
val project : t -> Vector2i.t
Projects a vector on the plane z = 0
See : OgamlMath.Vector2i
val lift : Vector2i.t -> t
Lifts a 2D vector in the 3D space by setting z = 0
See : OgamlMath.Vector2i
val dot : t -> t -> int
Computes the dot product of two vectors
val cross : t -> t -> t
Computes the cross product of two vectors
val angle : t -> t -> float
Computes the angle (in radians) between two vectors
val squared_norm : t -> int
Computes the squared norm of a vector
val norm : t -> float
Computes the norm of a vector
val squared_dist : t -> t -> int
Computes the squared distance between two points
val dist : t -> t -> float
Computes the distance between two points
val clamp : t -> t -> t -> t
clamp v a b returns the vector whose coordinates are the coordinates of v clamped between the coordinates of a and b
val map : t -> (int -> int) -> t
Maps each coordinate of a vector
val map2 : t -> t -> (int -> int -> int) -> t
Maps each pair of coordinates of two vectors
val max : t -> int
Returns the maximal coordinate of a vector
val min : t -> int
Returns the minimal coordinate of a vector
val raster : t -> t -> t list
raster p1 p2 applies the Bresenham's line algorithm between the pointsp1 and p2 and returns the list of points constituting the line
Note : should not be used for precise raytracing as it may miss points
val print : t -> string
Returns a pretty-printed string (not for serialization)