Abstract

A module type for standard Euclidean vectors.

Vectors of arbitrary dimension can be constructed with mk_vspace by passing in a vector and a real module, although for most uses the mk_vspace_2d and mk_vspace_3d modules are simpler and sufficient.

Synopsis

module type vspace = {
type real
type vector
val +: vector -> vector -> vector
val -: vector -> vector -> vector
val dot: vector -> vector -> real
val quadrance: vector -> real
val scale: real -> vector -> vector
val norm: vector -> real
val normalise: vector -> vector
}
module type vspace_2d = {
type real
include vspace with real = real with vector = {x: real, y: real}
}
module mk_vspace_2d: (real: real) -> vspace_2d with real = real.t
module type vspace_3d = {
type real
include vspace with real = real with vector = {x: real, y: real, z: real}
val cross: vector -> vector -> vector
}
module mk_vspace_3d: (real: real) -> vspace_3d with real = real.t
module mk_vspace: (V: vector) -> (real: real) -> vspace with real = real.t with vector = V.vector real.t

Description

module type vspace
type real
type vector

A vector type. Semantically a sequence of reals.

val +: vector -> vector -> vector
val -: vector -> vector -> vector
val dot: vector -> vector -> real

Inner product.

val quadrance: vector -> real

Squared norm.

val scale: real -> vector -> vector
val norm: vector -> real
val normalise: vector -> vector

Transform to unit vectortor.

module type vspace_2d

A two-dimensional vector space is just a vector space, but we give the vectors a convenient record type.

type real
include vspace with real = real with vector = {x: real, y: real}
module mk_vspace_2d

Construct a 2D vector space.

module type vspace_3d

A three-dimensional vector space is just a vector space, but we give the vectors a convenient record type. Also, cross product is defined.

type real
include vspace with real = real with vector = {x: real, y: real, z: real}
val cross: vector -> vector -> vector

Cross product.

module mk_vspace_3d

Construct a 3D vector space.

module mk_vspace

Construct an arbitrary-dimensional vector space. The dimensionality is given by the vector representation that is provided.