Module OgamlMath.Vector3f

Operations on immutable vectors of 3 floats

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

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

Vector operations

type t = {x : float; y : float; z : float}
Type of immutable vectors of 3 floats

Record fields

x : float
y : float
z : float
val make : float -> float -> float -> 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 : float -> t -> t
Multiplies a vector by a scalar
val div : float -> t -> t
Divides a vector by a scalar. Raises Vector3f_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 to_int : t -> Vector3i.t
Truncates the floating-point coordinates of a vector
See : OgamlMath.Vector3i
val from_int : Vector3i.t -> t
Returns a float vector from an int vector
See : OgamlMath.Vector3i
val project : t -> Vector2f.t
Projects a vector on the plane z = 0.
See : OgamlMath.Vector2f
val lift : Vector2f.t -> t
Lifts a 2D vector in the 3D space by setting z = 0.
See : OgamlMath.Vector2f
val dot : t -> t -> float
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 -> float
Computes the squared norm of a vector
val norm : t -> float
Computes the norm of a vector
val squared_dist : t -> t -> float
Computes the squared distance between two points
val dist : t -> t -> float
Computes the distance between two points
val normalize : t -> t
Normalizes a vector. Raises Vector3f_exception if the vector is zero.
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 -> (float -> float) -> t
Maps each coordinate of a vector
val map2 : t -> t -> (float -> float -> float) -> t
Maps each pair of coordinates of two vectors
val max : t -> float
Returns the maximal coordinate of a vector
val min : t -> float
Returns the minimal coordinate of a vector
val print : t -> string
Returns a pretty-printed string (not for serialization)
val direction : t -> t -> t
direction u v returns the normalized direction vector from u to v . Raises Vector3f_exception if u = v .
val endpoint : t -> t -> float -> t
endpoint a v t returns the point a + tv
val raytrace_points : t -> t -> (float * t * t) list
raytrace_points p1 p2 returns the list of integer-valued points (cubes) on the line from p1 to p2
Each point is a triple of the form (t, p, f) such that :
t is the time at the intersection between the line and the point
p stores the (integer) coordinates of the point
f is a unit vector indicating which face of the cube has been intersected
val raytrace : t -> t -> float -> (float * t * t) list
raytrace p v t applies raytrace_points between the points p and p + tv . The intersection times are comprised between 0 and t