Module Gg.V2
type t= v2The type for 2D vectors.
val dim : intdimis the dimension of vectors of typev2.
type m= m2The type for matrices representing linear transformations of 2D space.
Constructors, accessors and constants
val v : float -> float -> v2v x yis the vector(x y).
val comp : int -> v2 -> floatcomp i visvi, theith component ofv.- raises Invalid_argument
if
iis not in [0;dim[.
val x : v2 -> floatx vis the x component ofv.
val y : v2 -> floaty vis the y component ofv.
val ox : v2oxis the unit vector(1. 0.).
val oy : v2oyis the unit vector(0. 1.).
val infinity : v2infinityis the vector whose components areinfinity.
val neg_infinity : v2neg_infinityis the vector whose components areneg_infinity.
val basis : int -> v2basis iis theith vector of an orthonormal basis of the vector spacetwith inner productdot.- raises Invalid_argument
if
iis not in [0;dim[.
val of_tuple : (float * float) -> v2of_tuple (x, y)isV2.v x y.
val to_tuple : v2 -> float * floatof_tuple vis(V2.x v, V2.y v).
val of_polar : v2 -> v2of_polar pvis 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 -> v2to_polar vis a vector whose coordinates(r, theta)are the radial and angular polar coordinates ofv.thetais in [-pi;pi].
Functions
val dot : v2 -> v2 -> floatdot u vis the dot productu.v.
val norm : v2 -> floatnorm vis the norm|v| = sqrt v.v.
val norm2 : v2 -> floatnorm2 vis the squared norm|v|2 .
val polar : float -> float -> v2polar r thetaisV2.of_polar (V2.v r theta).
val angle : v2 -> floatangle vis the angular polar coordinates ofv. The result is in [-pi;pi].
val ltr : m2 -> v2 -> v2ltr m vis the linear transformmv.
val tr : m3 -> v2 -> v2tr m vis the affine transform in homogenous 2D space of the vectorvbym.Note. Since
mis supposed to be affine the function ignores the last row ofm.vis treated as a vector (infinite point, its last coordinate in homogenous space is 0) and is thus translationally invariant. UseP2.trto transform finite points.
Overridden Pervasives operators
Traversal
val mapi : (int -> float -> float) -> v2 -> v2mapi f vis likemapbut the component index is also given.
val fold : ('a -> float -> 'a) -> 'a -> v2 -> 'afold f acc visf (...(f (f acc v0) v1)...).
val foldi : ('a -> int -> float -> 'a) -> 'a -> v2 -> 'afoldi f acc visf (...(f (f acc 0 v0) 1 v1)...).
val iter : (float -> unit) -> v2 -> unititer f visf v0; f v1;...
val iteri : (int -> float -> unit) -> v2 -> unititeri f visf 0 v0; f 1 v1;...
Predicates and comparisons
val for_all : (float -> bool) -> v2 -> boolfor_all p visp v0&& p v1&&...
val exists : (float -> bool) -> v2 -> boolexists p visp v0|| p v1||...
Printers
val pp : Stdlib.Format.formatter -> v2 -> unitpp ppf vprints a textual representation ofvonppf.
val pp_f : (Stdlib.Format.formatter -> float -> unit) -> Stdlib.Format.formatter -> v2 -> unitpp_f pp_comp ppf vprintsvlikeppbut usespp_compto print floating point values.