123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295(** Two-dimensional vector
@canonical OCADml.v2 *)typev2=Gg.v2(** Three-dimensional vector
@canonical OCADml.v3 *)typev3=Gg.v3(** Four-dimensional vector
@canonical OCADml.v4 *)typev4=Gg.v4let[@inline]v2xy=Gg.V2.vxylet[@inline]v3xyz=Gg.V3.vxyzlet[@inline]v4xyzw=Gg.V4.vxyzwmoduletypeS=sigtypet(** Zero vector *)valzero:t(** A line segment between two points. *)typeline={a:t;b:t}(** {1 Comparison} *)(** [equal a b]
Float equality between the vectors [a] and [b]. *)valequal:t->t->bool(** [compare a b]
Compare the vectors [a] and [b]. *)valcompare:t->t->int(** [approx ?eps a b]
Returns true if the distance between vectors [a] and [b] is less than or
equal to the epsilon [eps]. *)valapprox:?eps:float->t->t->bool(** {1 Basic Arithmetic} *)(** [horizontal_op f a b]
Hadamard (element-wise) operation between vectors [a] and [b] using the
function [f]. *)valhorizontal_op:(float->float->float)->t->t->t(** [add a b]
Hadamard (element-wise) addition of vectors [a] and [b]. *)valadd:t->t->t(** [sub a b]
Hadamard (element-wise) subtraction of vector [b] from [a]. *)valsub:t->t->t(** [mul a b]
Hadamard (element-wise) product of vectors [a] and [b]. *)valmul:t->t->t(** [div a b]
Hadamard (element-wise) division of vector [a] by [b]. *)valdiv:t->t->t(** [neg t]
Negation of all elements of [t]. *)valneg:t->t(** [add_scalar t s]
Element-wise addition of [s] to [t]. *)valsadd:t->float->t(** [sub_scalar t s]
Element-wise subtraction of [s] from [t]. *)valssub:t->float->t(** [mul_scalar t s]
Element-wise multiplication of [t] by [s]. *)valsmul:t->float->t(** [div_scalar t s]
Element-wise division of [t] by [s]. *)valsdiv:t->float->t(** [abs t]
Calculate the absolute value of the vector [t]. *)valabs:t->t(** {1 Vector Math} *)(** [norm t]
Calculate the vector norm (a.k.a. magnitude) of [t]. *)valnorm:t->float(** [distance a b]
Calculate the magnitude of the difference (Hadamard subtraction) between [a]
and [b]. *)valdistance:t->t->float(** [normalize t]
Normalize [t] to a vector for which the magnitude is equal to 1.
e.g. [norm (normalize t) = 1.] *)valnormalize:t->t(** [dot a b]
Vector dot product of [a] and [b]. *)valdot:t->t->float(** [cross a b]
Vector cross product of [a] and [b]. In the case of 2d vectors, the cross
product is performed with an assumed z = 0. *)valcross:t->t->v3(** [mid a b]
Compute the midpoint between the vectors [a] and [b]. *)valmid:t->t->t(** [mean l]
Calculate the mean / average of all vectors in [l]. *)valmean:tlist->t(** [mean' a]
Calculate the mean / average of all vectors in the array [a]. *)valmean':tarray->t(** [angle a b]
Calculate the angle between the vectors [a] and [b]. *)valangle:t->t->float(** [angle_points a b c]
Calculate the angle between the points [a], [b], and [c]. *)valangle_points:t->t->t->float(** [ccw_theta t]
Calculate the angle in radians counter-clockwise [t] is from the positive
x-axis along the xy plane. *)valccw_theta:t->float(** [vector_axis a b]
Compute the vector perpendicular to the vectors [a] and [b]. *)valvector_axis:t->t->v3(** [clockwise_sign ?eps a b c]
Returns the rotational ordering (around the z-axis, from the perspective of
the origin, looking "up" the z-axis) of the points [a], [b], and [c] as a
signed float, [1.] for clockwise, and [-1.] for counter-clockwise. If the
points are collinear (not forming a valid triangle, within the tolerance of
[eps]), [0.] is returned. *)valclockwise_sign:?eps:float->t->t->t->float(** [collinear p1 p2 p3]
Returns [true] if [p2] lies on the line between [p1] and [p3]. *)valcollinear:t->t->t->bool(** [lerp a b u]
Linearly interpolate between vectors [a] and [b]. *)vallerp:t->t->float->t(** [lerpn a b n]
Linearly interpolate [n] vectors between vectors [a] and [b]. If [endpoint]
is [true], the last vector will be equal to [b], otherwise, it will be about
[a + (b - a) * (1 - 1 / n)]. *)vallerpn:?endpoint:bool->t->t->int->tlist(** [distance_to_vector p v]
Distance from point [p] to the line passing through the origin with unit
direction [v]. *)valdistance_to_vector:t->t->float(** [distance_to_line ?bounds ~line t]
Distance between the vector [t], and any point on [line]. [bounds]
indicates whether each end [{a; b}] of [line] is bounded, or a ray (default
= [(false, false)], indicating an infinite line in both directions.). *)valdistance_to_line:?bounds:bool*bool->line:line->t->float(** [point_on_line ?eps ?bounds ~line t]
Return [true] if the point [t] falls within [eps] distance of the [line].
[bounds] indicates whether each end [{a; b}] of [line] is bounded, or a ray
(default = [(false, false)], indicating an infinite line in both
directions.) *)valpoint_on_line:?eps:float->?bounds:bool*bool->line:line->t->bool(** [line_closest_point ?bounds ~line t]
Find the closest point to [t] lying on the provided [line]. [bounds]
indicates whether each end [{a; b}] of [line] is bounded, or a ray (default =
[(false, false)], indicating an infinite line in both directions.) *)valline_closest_point:?bounds:bool*bool->line:line->t->t(** [lower_bounds a b]
Compute the lower bounds (minima of each dimension) of the vectors [a] and [b]. *)vallower_bounds:t->t->t(** [upper_bounds a b]
Compute the upper bounds (maxima of each dimension) of the vectors [a] and [b]. *)valupper_bounds:t->t->t(** {1 Utilities} *)valmap:(float->float)->t->tvalx:t->floatvaly:t->floatvalz:t->floatvalto_v2:t->v2valto_string:t->string(** [deg_of_rad t]
Element-wise conversion of [t] from radians to degrees. *)valdeg_of_rad:t->t(** [rad_to_deg t]
Element-wise conversion of [t] from degrees to radians. *)valrad_of_deg:t->t(** {1 Infix operations} *)(** [a +@ b]
Hadamard (element-wise) addition of [a] and [b]. *)val(+@):t->t->t(** [a -@ b]
Hadamard (element-wise) subtraction of [b] from [a]. *)val(-@):t->t->t(** [a *@ b]
Hadamard (element-wise) product of [a] and [b]. *)val(*@):t->t->t(** [a /@ b]
Hadamard (element-wise) division of [a] by [b]. *)val(/@):t->t->t(** [t +$ s]
Scalar addition of the vector [t] and scalar [s]. *)val(+$):t->float->t(** [t -$ s]
Scalar subtraction of the scalar [s] from the vector [t]. *)val(-$):t->float->t(** [t *$ s]
Scalar multiplication of the vector [t] by the scalar [s]. *)val(*$):t->float->t(** [t /$ s]
Scalar division of the vector [t] by the scalar [s]. *)val(/$):t->float->tend