Liking cljdoc? Tell your friends :D

fastmath.vector

Mathematical vector operations.

Types

  • Fixed size (custom types):
    • Vec2 - 2d vector, creator vec2
    • Vec3 - 3d vector, creator vec3
    • Vec4 - 4d vector, creator vec4
    • ArrayVec - fixed size vector as double array, n-dimensional, creator [[arrayvec]]
  • Variable size:
    • Clojure's PersistentVector, creator [].

VectorProto defines most of the functions.

Vectors implements also:

  • Sequable
  • Sequencial
  • IFn
  • Counted
  • equals and toString from Object

That means that vectors can be destructured, treated as sequence or called as a function. See vec2 for examples.

Mathematical vector operations.

### Types

* Fixed size (custom types):
    * Vec2 - 2d vector, creator [[vec2]]
    * Vec3 - 3d vector, creator [[vec3]]
    * Vec4 - 4d vector, creator [[vec4]]
    * ArrayVec - fixed size vector as double array, n-dimensional, creator [[arrayvec]]
* Variable size:
    * Clojure's PersistentVector, creator `[]`.

[[VectorProto]] defines most of the functions.

Vectors implements also:

* `Sequable`
* `Sequencial`
* `IFn`
* `Counted`
* `equals` and `toString` from `Object`

That means that vectors can be destructured, treated as sequence or called as a function. See [[vec2]] for examples.
raw docstring

aligned?clj

(aligned? v1 v2)

Are vectors aligned (have the same direction)?

Are vectors aligned (have the same direction)?
sourceraw docstring

angle-betweenclj

(angle-between v1 v2)

Angle between two vectors

See also relative-angle-between.

Angle between two vectors

See also [[relative-angle-between]].
sourceraw docstring

array->vec2clj

(array->vec2 a)

Doubles array to Vec2

Doubles array to Vec2
sourceraw docstring

array->vec3clj

(array->vec3 a)

Doubles array to Vec3

Doubles array to Vec3
sourceraw docstring

array->vec4clj

(array->vec4 a)

Doubles array to Vec4

Doubles array to Vec4
sourceraw docstring

array-vecclj

(array-vec xs)

Make ArrayVec type based on provided sequence xs.

Make ArrayVec type based on provided sequence `xs`.
sourceraw docstring

average-vectorsclj

(average-vectors vs)
(average-vectors init vs)

Average / centroid of vectors. Input: initial vector (optional), list of vectors

Average / centroid of vectors. Input: initial vector (optional), list of vectors
sourceraw docstring

distclj

(dist v1 v2)

Euclidean distance between vectors

Euclidean distance between vectors
sourceraw docstring

dist-absclj

(dist-abs v1 v2)

Manhattan distance between vectors

Manhattan distance between vectors
sourceraw docstring

dist-canberraclj

(dist-canberra v1 v2)

Canberra distance

Canberra distance
sourceraw docstring

dist-chebclj

(dist-cheb v1 v2)

Chebyshev distance between 2d vectors

Chebyshev distance between 2d vectors
sourceraw docstring

dist-cosclj

(dist-cos v1 v2)

Cosine distance

Cosine distance
sourceraw docstring

dist-discreteclj

(dist-discrete v1 v2)

Discrete distance between 2d vectors

Discrete distance between 2d vectors
sourceraw docstring

dist-emdclj

(dist-emd v1 v2)

Earth Mover's Distance

Earth Mover's Distance
sourceraw docstring

dist-sqclj

(dist-sq v1 v2)

Squared Euclidean distance between vectors

Squared Euclidean distance between vectors
sourceraw docstring

distancesclj

source

edivclj

(ediv v1 v2)

Element-wise division of two vectors.

Element-wise division of two vectors.
sourceraw docstring

faceforwardclj

(faceforward n v)

Flip normal n to match the same direction as v.

Flip normal `n` to match the same direction as `v`.
sourceraw docstring

generate-vec2clj

(generate-vec2 f)
(generate-vec2 f1 f2)

Generate Vec2 with fn(s)

Generate Vec2 with fn(s)
sourceraw docstring

generate-vec3clj

(generate-vec3 f)
(generate-vec3 f1 f2 f3)

Generate Vec3 with fn(s)

Generate Vec3 with fn(s)
sourceraw docstring

generate-vec4clj

(generate-vec4 f)
(generate-vec4 f1 f2 f3 f4)

Generate Vec4 with fn(s)

Generate Vec4 with fn(s)
sourceraw docstring

limitclj

(limit v len)

Limit length of the vector by given value

Limit length of the vector by given value
sourceraw docstring

normalizeclj

(normalize v)

Normalize vector (set length = 1.0)

Normalize vector (set length = 1.0)
sourceraw docstring

relative-angle-betweenclj

(relative-angle-between v1 v2)

Angle between two vectors relative to each other.

See also angle-between.

Angle between two vectors relative to each other.

See also [[angle-between]].
sourceraw docstring

set-magclj

(set-mag v len)

Set length of the vector

Set length of the vector
sourceraw docstring

TOLERANCEclj

Tolerance used in [[is-near-zero?]]. Values less than this value are treated as zero.

Tolerance used in [[is-near-zero?]]. Values less than this value are treated as zero.
sourceraw docstring

vec2clj

(vec2 x y)

Make 2d vector

Make 2d vector
sourceraw docstring

vec3clj

(vec3 v z)
(vec3 x y z)

Make Vec2 vector

Make Vec2 vector
sourceraw docstring

vec4clj

(vec4 v w)
(vec4 v z w)
(vec4 x y z w)

Make Vec4 vector

Make Vec4 vector
sourceraw docstring

VectorProtocljprotocol

Vector operations

Vector operations

to-vecclj

(to-vec v)

Convert to Clojure primitive vector Vec.

Convert to Clojure primitive vector `Vec`.

dotclj

(dot v1 v2)

Dot product of two vectors.

Dot product of two vectors.

permuteclj

(permute v idxs)

Permute vector elements with given indices.

Permute vector elements with given indices.

applyfclj

(applyf v f)

Apply function to all vector values (like map but returns the same type).

Apply function to all vector values (like map but returns the same type).

addclj

(add v1)
(add v1 v2)

Sum of two vectors.

Sum of two vectors.

approxclj

(approx v)
(approx v d)

Round to 2 (or d) decimal places

Round to 2 (or `d`) decimal places

crossclj

(cross v1 v2)

Cross product

Cross product

reciprocalclj

(reciprocal v)

Reciprocal of elements.

Reciprocal of elements.

sumclj

(sum v1)

Sum of elements

Sum of elements

emnclj

(emn v1 v2)

Element-wise min from two vectors.

Element-wise min from two vectors.

is-near-zero?clj

(is-near-zero? v1)

Is vector almost zero? (all absolute values of elements are less than TOLERANCE)

Is vector almost zero? (all absolute values of elements are less than `TOLERANCE`)

headingclj

(heading v1)

Angle between vector and unit vector [1,0,...]

Angle between vector and unit vector `[1,0,...]`

axis-rotateclj

(axis-rotate v1 angle axis)
(axis-rotate v1 angle axis pivot)

Rotate around axis, 3d only

Rotate around axis, 3d only

magsqclj

(magsq v1)

Length of the vector squared.

Length of the vector squared.

to-polarclj

(to-polar v1)

To polar coordinates (2d, 3d only), first element is length, the rest angle.

To polar coordinates (2d, 3d only), first element is length, the rest angle.

transformclj

(transform v1 o vx vy)
(transform v1 o vx vy vz)

Transform vector; map point to coordinate system defined by origin, vx and vy (as bases), 2d and 3d only.

Transform vector; map point to coordinate system defined by origin, vx and vy (as bases), 2d and 3d only.

magclj

(mag v1)

length of the vector.

length of the vector.

from-polarclj

(from-polar v1)

From polar coordinates (2d, 3d only)

From polar coordinates (2d, 3d only)

subclj

(sub v1)
(sub v1 v2)

Subtraction of two vectors.

Subtraction of two vectors.

mindimclj

(mindim v)

Index of minimum value.

Index of minimum value.

is-zero?clj

(is-zero? v1)

Is vector zero?

Is vector zero?

econstrainclj

(econstrain v val1 val2)

Element-wise constrain

Element-wise constrain

base-fromclj

(base-from v)

List of perpendicular vectors (basis)

List of perpendicular vectors (basis)

emultclj

(emult v1 v)

Element-wise vector multiplication (Hadamard product).

Element-wise vector multiplication (Hadamard product).

maxdimclj

(maxdim v)

Index of maximum value.

Index of maximum value.

emxclj

(emx v1 v2)

Element-wise max from two vectors.

Element-wise max from two vectors.

interpolateclj

(interpolate v1 v2 t)
(interpolate v1 v2 t f)

Interpolate vectors, optionally set interpolation fn

Interpolate vectors, optionally set interpolation fn

perpendicularclj

(perpendicular v1)
(perpendicular v1 v2)

Perpendicular vector (only 2d).

Perpendicular vector (only 2d).

divclj

(div v1 v)

Divide vector by number v

Divide vector by number `v`

mnclj

(mn v1)

Minimum value of vector elements

Minimum value of vector elements

absclj

(abs v1)

Absolute value of vector elements

Absolute value of vector elements

einterpolateclj

(einterpolate v1 v2 v)
(einterpolate v1 v2 v f)

Interpolate vectors element-wise, optionally set interpolation fn

Interpolate vectors element-wise, optionally set interpolation fn

mxclj

(mx v1)

Maximum value of vector elements

Maximum value of vector elements

multclj

(mult v1 v)

Multiply vector by number v.

Multiply vector by number `v`.

rotateclj

(rotate v1 angle)
(rotate v1 anglex angley anglez)

Rotate vector

Rotate vector
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close