module Vector:sig
..end
Vector
contains the Vector.t
type and functions for
creating and manipulating vectors.
typet =
float * float
val to_string : t -> string
to_string vec
is the string representation of vec
.
val (~<) : t -> float
~< (x, y)
is x
.
val (~>) : t -> float
~> (x, y)
is y
.
val create : float -> float -> t
create x y
is (x, y)
.
val of_tuple : float * float -> t
of_tuple (x, y)
is (x, y)
.
val of_angle : float -> t
of_angle theta
is the unit vector (cos theta, sin theta)
.
val mag : t -> float
mag vec
is the magnitude of vec
, i.e. sqrt (x**2. +. y**2.)
val mag_sq : t -> float
mag_sq vec
is the squared magnitude of vec
, i.e. x**2. +. y**2.
.
This computation is faster than mag
.
val add : t -> t -> t
add v1 v2
is the sum of v1
and v2
.
val sub : t -> t -> t
sub v1 v2
is the difference between v1
and v2
, which is
equivalent to add v1 (mult v2 (-1.))
.
val mult : t -> float -> t
mult vec f
is the scalar multiplication of vec
by f
.
val div : t -> float -> t
div vec f
is mult vec (1. /. f)
.
val dist : t -> t -> float
dist v1 v2
is the distance between v1
and v2
, which is equivalent
to mag (sub v1 v2)
.
val dot : t -> t -> float
dot v1 v2
is the dot product of v1
and v2
, i.e.
(x1 *. x2) +. (y1 *. y2)
, where v1 = (x1, y1)
and v2 = (x2, y2)
.
val norm : t -> t
norm vec
is vec
with a magnitude of 1.
, which is equivalent to
div vec (mag vec)
.
val with_mag : t -> float -> t
with_mag vec f
is vec
with a magnitude of f
, which is equivalent
to mult (norm vec) f
.
val limit : t -> float -> t
limit vec f
is vec
with a maximum magnitude of f
, which is
equivalent to with_mag vec (min (mag vec) f)
.
val heading : t -> float
heading vec
is the heading of vec
, i.e. atan2 y x
where
vec = (x, y)
.
val rotate : t -> float -> t
rotate vec theta
is vec
rotated by angle theta
.
val lerp : t -> t -> float -> t
lerp v1 v2 t
is the linear interpolation from v1
to v2
by t
,
where t
is in [0, 1]
.
val angle_between : t -> t -> float
angle_between v1 v2
is the smallest angle between v1
and v2
.
val project : t -> t -> t
project v1 v2
is the projection of v1
on to v2
.
val (++) : t -> t -> t
v1 ++ v2
is add v1 v2
.
val (--) : t -> t -> t
v1 -- v2
is sub v1 v2
.
val ( *** ) : t -> float -> t
vec *** f
is mult vec f
.
val (//) : t -> float -> t
vec // f
is div vec f
.
val ( **. ) : t -> t -> float
v1 **. v2
is dot v1 v2
.
val (~||) : t -> float
~|| vec
is mag vec
.