Module Gg.V2
type t
= v2
The type for 2D vectors.
val dim : int
dim
is the dimension of vectors of typev2
.
type m
= m2
The type for matrices representing linear transformations of 2D space.
Constructors, accessors and constants
val v : float -> float -> v2
v x y
is the vector(x y)
.
val comp : int -> v2 -> float
comp i v
isv
i
, thei
th component ofv
.- raises Invalid_argument
if
i
is not in [0;
dim
[.
val x : v2 -> float
x v
is the x component ofv
.
val y : v2 -> float
y v
is the y component ofv
.
val ox : v2
ox
is the unit vector(1. 0.)
.
val oy : v2
oy
is the unit vector(0. 1.)
.
val infinity : v2
infinity
is the vector whose components areinfinity
.
val neg_infinity : v2
neg_infinity
is the vector whose components areneg_infinity
.
val basis : int -> v2
basis i
is thei
th vector of an orthonormal basis of the vector spacet
with inner productdot
.- raises Invalid_argument
if
i
is not in [0;
dim
[.
val of_tuple : (float * float) -> v2
of_tuple (x, y)
isV2.v x y
.
val to_tuple : v2 -> float * float
of_tuple v
is(V2.x v, V2.y v
).
val of_polar : v2 -> 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 : v2 -> v2
to_polar v
is a vector whose coordinates(r, theta)
are the radial and angular polar coordinates ofv
.theta
is in [-pi;pi
].
Functions
val dot : v2 -> v2 -> float
dot u v
is the dot productu.v
.
val norm : v2 -> float
norm v
is the norm|v| = sqrt v.v
.
val norm2 : v2 -> float
norm2 v
is the squared norm|v|
2 .
val polar : float -> float -> v2
polar r theta
isV2.of_polar (V2.v r theta)
.
val angle : v2 -> float
angle v
is the angular polar coordinates ofv
. The result is in [-pi;pi
].
val ltr : m2 -> v2 -> v2
ltr m v
is the linear transformmv
.
val tr : m3 -> v2 -> v2
tr m v
is the affine transform in homogenous 2D space of the vectorv
bym
.Note. Since
m
is supposed to be affine the function ignores the last row ofm
.v
is treated as a vector (infinite point, its last coordinate in homogenous space is 0) and is thus translationally invariant. UseP2.tr
to transform finite points.
Overridden Pervasives
operators
Traversal
val mapi : (int -> float -> float) -> v2 -> v2
mapi f v
is likemap
but the component index is also given.
val fold : ('a -> float -> 'a) -> 'a -> v2 -> 'a
fold f acc v
isf (
...(f (f acc v
0) v
1)
...)
.
val foldi : ('a -> int -> float -> 'a) -> 'a -> v2 -> 'a
foldi f acc v
isf (
...(f (f acc 0 v
0) 1 v
1)
...)
.
val iter : (float -> unit) -> v2 -> unit
iter f v
isf v
0; f v
1;
...
val iteri : (int -> float -> unit) -> v2 -> unit
iteri f v
isf 0 v
0; f 1 v
1;
...
Predicates and comparisons
val for_all : (float -> bool) -> v2 -> bool
for_all p v
isp v
0&& p v
1&&
...
val exists : (float -> bool) -> v2 -> bool
exists p v
isp v
0|| p v
1||
...
Printers
val pp : Stdlib.Format.formatter -> v2 -> unit
pp ppf v
prints a textual representation ofv
onppf
.
val pp_f : (Stdlib.Format.formatter -> float -> unit) -> Stdlib.Format.formatter -> v2 -> unit
pp_f pp_comp ppf v
printsv
likepp
but usespp_comp
to print floating point values.