Module Gg.V3
type t
= v3
The type for 3D vectors.
val dim : int
dim
is the dimension of vectors of typev3
.
type m
= m3
The type for matrices representing linear transformations of 3D space.
Constructors, accessors and constants
val v : float -> float -> float -> v3
v x y z
is the vector(x y z)
.
val comp : int -> v3 -> float
comp i v
isv
i
, thei
th component ofv
.- raises Invalid_argument
if
i
is not in [0;
dim
[.
val x : v3 -> float
x v
is the x component ofv
.
val y : v3 -> float
y v
is the y component ofv
.
val z : v3 -> float
z v
is the z component ofv
.
val ox : v3
ox
is the unit vector(1. 0. 0.)
.
val oy : v3
oy
is the unit vector(0. 1. 0.)
.
val oz : v3
oz
is the unit vector(0. 0. 1.)
.
val infinity : v3
infinity
is the vector whose components areinfinity
.
val neg_infinity : v3
neg_infinity
is the vector whose components areneg_infinity
.
val basis : int -> v3
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 * float) -> v3
of_tuple (x, y, z)
isv x y z
.
val to_tuple : v3 -> float * float * float
to_tuple v
is(x v, y v, z v)
.
val of_spherical : v3 -> v3
of_spherical sv
is the vector whose cartesian coordinates(x, y, z)
correspond to the radial, azimuth angle and zenith angle spherical coordinates(r, theta, phi)
given by(V3.x sv, V2.y sv, V3.z sv)
.
val to_spherical : v3 -> v3
to_spherical v
is the vector whose coordinate(r, theta, phi)
are the radial, azimuth angle and zenith angle spherical coordinates ofv
.theta
is in [-pi;pi
] andphi
in [0;pi
].
Functions
val cross : v3 -> v3 -> v3
cross u v
is the cross productu x v
.
val dot : v3 -> v3 -> float
dot u v
is the dot productu.v
.
val norm : v3 -> float
norm v
is the norm|v| = sqrt v.v
.
val norm2 : v3 -> float
norm2 v
is the squared norm|v|
2 .
val spherical : float -> float -> float -> v3
spherical r theta phi
isof_spherical (V3.v r theta phi)
.
val azimuth : v3 -> float
azimuth v
is the azimuth angle spherical coordinates ofv
. The result is in [-pi;pi
].
val zenith : v3 -> float
zenith v
is the zenith angle spherical coordinates ofv
. The result is in [0;pi
].
val ltr : m3 -> v3 -> v3
ltr m v
is the linear transformmv
.
val tr : m4 -> v3 -> v3
tr m v
is the affine transform in homogenous 3D 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. UseP3.tr
to transform finite points.
Overridden Pervasives
operators
Traversal
val mapi : (int -> float -> float) -> v3 -> v3
mapi f v
is likemap
but the component index is also given.
val fold : ('a -> float -> 'a) -> 'a -> v3 -> 'a
fold f acc v
isf (
...(f (f acc v
0) v
1)
...)
.
val foldi : ('a -> int -> float -> 'a) -> 'a -> v3 -> 'a
foldi f acc v
isf (
...(f (f acc 0 v
0) 1 v
1)
...)
.
val iter : (float -> unit) -> v3 -> unit
iter f v
isf v
0; f v
1;
...
val iteri : (int -> float -> unit) -> v3 -> unit
iteri f v
isf 0 v
0; f 1 v
1;
...
Predicates and comparisons
val for_all : (float -> bool) -> v3 -> bool
for_all p v
isp v
0&& p v
1&&
...
val exists : (float -> bool) -> v3 -> bool
exists p v
isp v
0|| p v
1||
...
Printers
val pp : Stdlib.Format.formatter -> v3 -> unit
pp ppf v
prints a textual representation ofv
onppf
.
val pp_f : (Stdlib.Format.formatter -> float -> unit) -> Stdlib.Format.formatter -> v3 -> unit
pp_f pp_comp ppf v
printsv
likepp
but usespp_comp
to print floating point values.