Module Gg.V2

module V2: sig .. end

type t = Gg.v2 
The type for 2D vectors.
val dim : int
dim is the dimension of vectors of type Gg.v2.
type m = Gg.m2 
The type for matrices representing linear transformations of 2D space.

Constructors, accessors and constants

val v : float -> float -> Gg.v2
v x y is the vector (x y).
val comp : int -> Gg.v2 -> float
comp i v is vi, the ith component of v.
Raises Invalid_argument if i is not in [0;Gg.V2.dim[.
val x : Gg.v2 -> float
x v is the x component of v.
val y : Gg.v2 -> float
y v is the y component of v.
val ox : Gg.v2
ox is the unit vector (1. 0.).
val oy : Gg.v2
oy is the unit vector (0. 1.).
val zero : Gg.v2
zero is the neutral element for Gg.V2.add.
val infinity : Gg.v2
infinity is the vector whose components are infinity.
val neg_infinity : Gg.v2
neg_infinity is the vector whose components are neg_infinity.
val basis : int -> Gg.v2
basis i is the ith vector of an orthonormal basis of the vector space Gg.V2.t with inner product
Raises Invalid_argument if i is not in [0;Gg.V2.dim[.
val of_tuple : float * float -> Gg.v2
of_tuple (x, y) is V2.v x y.
val to_tuple : Gg.v2 -> float * float
of_tuple v is (V2.x v, V2.y v).
val of_polar : Gg.v2 -> Gg.v2
of_polar pv is a vector whose cartesian coordinates (x, y) correspond to the radial and angular polar coordinates (r, theta) given by (V2.x pv, V2.y pv).
val to_polar : Gg.v2 -> Gg.v2
to_polar v is a vector whose coordinates (r, theta) are the radial and angular polar coordinates of v. theta is in [-pi;pi].
val of_v3 : Gg.v3 -> Gg.v2
of_v3 u is v (V3.x u) (V3.y u).
val of_v4 : Gg.v4 -> Gg.v2
of_v4 u is v (V4.x u) (V4.y u).


val neg : Gg.v2 -> Gg.v2
neg v is the inverse vector -v.
val add : Gg.v2 -> Gg.v2 -> Gg.v2
add u v is the vector addition u + v.
val sub : Gg.v2 -> Gg.v2 -> Gg.v2
sub u v is the vector subtraction u - v.
val mul : Gg.v2 -> Gg.v2 -> Gg.v2
mul u v is the component wise multiplication u * v.
val div : Gg.v2 -> Gg.v2 -> Gg.v2
div u v is the component wise division u / v.
val smul : float -> Gg.v2 -> Gg.v2
smul s v is the scalar multiplication sv.
val half : Gg.v2 -> Gg.v2
half v is the half vector smul 0.5 v.
val dot : Gg.v2 -> Gg.v2 -> float
dot u v is the dot product u.v.
val norm : Gg.v2 -> float
norm v is the norm |v| = sqrt v.v.
val norm2 : Gg.v2 -> float
norm2 v is the squared norm |v|2 .
val unit : Gg.v2 -> Gg.v2
unit v is the unit vector v/|v|.
val polar : float -> float -> Gg.v2
polar r theta is V2.of_polar (V2.v r theta).
val angle : Gg.v2 -> float
angle v is the angular polar coordinates of v. The result is in [-pi;pi].
val ortho : Gg.v2 -> Gg.v2
ortho v is v rotated by pi / 2.
val homogene : Gg.v2 -> Gg.v2
homogene v is the vector v/vy if vy <> 0 and v otherwise.
val mix : Gg.v2 -> Gg.v2 -> float -> Gg.v2
mix u v t is the linear interpolation u + t(v - u).
val ltr : Gg.m2 -> Gg.v2 -> Gg.v2
ltr m v is the linear transform mv.
val tr : Gg.m3 -> Gg.v2 -> Gg.v2
tr m v is the affine transform in homogenous 2D space of the vector v by m.

Note. Since m is supposed to be affine the function ignores the last row of m. v is treated as a vector (infinite point, its last coordinate in homogenous space is 0) and is thus translationally invariant. Use to transform finite points.

Overridden Pervasives operators

val (+) : Gg.v2 -> Gg.v2 -> Gg.v2
u + v is add u v.
val (-) : Gg.v2 -> Gg.v2 -> Gg.v2
u - v is sub u v.
val ( * ) : float -> Gg.v2 -> Gg.v2
t * v is smul t v.
val (/) : Gg.v2 -> float -> Gg.v2
v / t is smul (1. /. t) v.


val map : (float -> float) -> Gg.v2 -> Gg.v2
map f v is the component wise application of f to v.
val mapi : (int -> float -> float) -> Gg.v2 -> Gg.v2
mapi f v is like but the component index is also given.
val fold : ('a -> float -> 'a) -> 'a -> Gg.v2 -> 'a
fold f acc v is f (...(f (f acc v0) v1)...).
val foldi : ('a -> int -> float -> 'a) -> 'a -> Gg.v2 -> 'a
foldi f acc v is f (...(f (f acc 0 v0) 1 v1)...).
val iter : (float -> unit) -> Gg.v2 -> unit
iter f v is f v0; f v1; ...
val iteri : (int -> float -> unit) -> Gg.v2 -> unit
iteri f v is f 0 v0; f 1 v1; ...

Predicates and comparisons

val for_all : (float -> bool) -> Gg.v2 -> bool
for_all p v is p v0 && p v1 && ...
val exists : (float -> bool) -> Gg.v2 -> bool
exists p v is p v0 || p v1 || ...
val equal : Gg.v2 -> Gg.v2 -> bool
equal u v is u = v.
val equal_f : (float -> float -> bool) -> Gg.v2 -> Gg.v2 -> bool
equal_f eq u v tests u and v like Gg.V2.equal but uses eq to test floating point values.
val compare : Gg.v2 -> Gg.v2 -> int
compare u v is u v.
val compare_f : (float -> float -> int) -> Gg.v2 -> Gg.v2 -> int
compare_f cmp u v compares u and v like but uses cmp to compare floating point values.


val pp : Format.formatter -> Gg.v2 -> unit
pp ppf v prints a textual representation of v on ppf.
val pp_f : (Format.formatter -> float -> unit) -> Format.formatter -> Gg.v2 -> unit
pp_f pp_comp ppf v prints v like Gg.V2.pp but uses pp_comp to print floating point values.