A collection of helper functions that work on vectors, both in the sense of a collection and in the directional sense.
A collection of helper functions that work on vectors, both in the sense of a collection and in the directional sense.
(* a b)
Component-wise multiplication of two n-dimensional vectors. If the second argument is a scalar, all components of the first argument gets multiplied by it.
** Example **
(some.vec/* [2 2][2 2])
;; (4 4)
(some.vec/* [2 2] 4)
;; (8 8)
Component-wise multiplication of two n-dimensional vectors. If the second argument is a scalar, all components of the first argument gets multiplied by it. ** Example ** ```clojure (some.vec/* [2 2][2 2]) ;; (4 4) (some.vec/* [2 2] 4) ;; (8 8) ```
(+ a b)
Adds two vectors of the same dimension together. If the second argument is a scalar, it gets added to all components of the first argument.
** Example **
(some.vec/+ [1 1][1 1])
;; (2 2)
(some.vec/+ [1 1] 2)
;; (3 3)
Adds two vectors of the same dimension together. If the second argument is a scalar, it gets added to all components of the first argument. ** Example ** ```clojure (some.vec/+ [1 1][1 1]) ;; (2 2) (some.vec/+ [1 1] 2) ;; (3 3) ```
(- a b)
Substracts 2 vectors of same dimension. If the second argument is a scalar, all components of the first argument gets subtracted by it.
** Example **
(some.vec/- [2 2][1 1])
;; (1 1)
(some.vec/- [5 5] 1)
;; (4 4)
Substracts 2 vectors of same dimension. If the second argument is a scalar, all components of the first argument gets subtracted by it. ** Example ** ```clojure (some.vec/- [2 2][1 1]) ;; (1 1) (some.vec/- [5 5] 1) ;; (4 4) ```
(/ a b)
Divides vector a by vector b. Both vectors should be of the same dimension. If the second argument is a scalar, all components of the first argument gets divided by it.
** Example **
(some.vec// [2 2][2 2])
;; (1 1)
(some.vec// [2 2] 2)
;; (1 1)
Divides vector a by vector b. Both vectors should be of the same dimension. If the second argument is a scalar, all components of the first argument gets divided by it. ** Example ** ```clojure (some.vec// [2 2][2 2]) ;; (1 1) (some.vec// [2 2] 2) ;; (1 1) ```
(angle v)
Returns the angle of a 2D vector in radians.
Returns the angle of a 2D vector in radians.
(angle-between v1 v2)
Returns the angle between two 2D vectors, calculated using the difference between their angles.
Returns the angle between two 2D vectors, calculated using the difference between their angles.
(average v)
Returns the average of a vector.
Returns the average of a vector.
(distance v1 v2)
Calculates the distance between two vectors of same dimension.
Calculates the distance between two vectors of same dimension.
(dot v1 v2)
Returns the dot product of two n-dimensional vectors.
Returns the dot product of two n-dimensional vectors.
(dx->x v)
(dx->x v start)
Treats each component of a vector as an interval and creates a running sum of the intervals.
For example: [1 1 1] -> [0 1 2 3] [1 2 3] -> [0 1 3 6]
Treats each component of a vector as an interval and creates a running sum of the intervals. For example: [1 1 1] -> [0 1 2 3] [1 2 3] -> [0 1 3 6]
(from-angle theta)
Returns a 2D unit vector with given angle
Returns a 2D unit vector with given angle
(from-polar theta radius)
Returns a 2D vector from polar coordinates
Returns a 2D vector from polar coordinates
(indexed coll)
pairs each element in a collection as an indexed tuple and return as vector
pairs each element in a collection as an indexed tuple and return as vector
(length v)
Returns the length of a vector of any dimension.
Returns the length of a vector of any dimension.
(limit v l)
If vector v is bigger than limit l, vector gets scaled to l.
If vector v is bigger than limit l, vector gets scaled to l.
(mat-trans mat)
Rotates an ND matrix (vec of vecs)
Rotates an ND matrix (vec of vecs)
(normalize v)
Returns a vector of any dimension normalized
Returns a vector of any dimension normalized
(normalize-range v)
Divides every element in vector by total sum
Divides every element in vector by total sum
(pad vector value)
(pad vector value pad-size)
pads start and end of vector with value and pad size
pads start and end of vector with value and pad size
(pad-end vector value)
(pad-end vector value pad-size)
pads end of vector with value and pad size
pads end of vector with value and pad size
(pad-start vector value)
(pad-start vector value pad-size)
pads start of vector with value and pad size
pads start of vector with value and pad size
(pad-wrap vector)
pads start of vector with end and end of vector with start
pads start of vector with end and end of vector with start
(random N)
(random N f)
Returns a random vector of N dimension. Values between 0 and 1. An optional second argument can be given as another RNG function.
Returns a random vector of N dimension. Values between 0 and 1. An optional second argument can be given as another RNG function.
(random-polar)
(random-polar f)
Returns a 2D vector from a random angle and radius between 0 and 1. An optional second argument can be given as another RNG function.
Returns a 2D vector from a random angle and radius between 0 and 1. An optional second argument can be given as another RNG function.
(random-replace vec value)
(random-replace vec value f)
Replace random element in vector with a value
Replace random element in vector with a value
(random10 N)
(random10 N f)
Returns a vector of size N of random 1s and 0s. An optional second argument can be given as another RNG function.
Returns a vector of size N of random 1s and 0s. An optional second argument can be given as another RNG function.
(range-fill vec start stop value)
Fill a range of elements in vector with value.
** Example **
(some.vec/range-fill [0 1 2 3 4 5] 2 4 69)
;; [0 1 69 69 69 5]
Fill a range of elements in vector with value. ** Example ** ```clojure (some.vec/range-fill [0 1 2 3 4 5] 2 4 69) ;; [0 1 69 69 69 5] ```
(range-replace vec value position)
replace elements of vector with another set at given position
replace elements of vector with another set at given position
(restv col)
returns the rest of a collection as a vector
returns the rest of a collection as a vector
(rotate v theta)
rotates a 2D vector by an angle
rotates a 2D vector by an angle
(select v a b)
Returns the selection of a vector from index a to and including index b.
Returns the selection of a vector from index a to and including index b.
(set-length v l)
Returns the vector v with given length l.
Returns the vector v with given length l.
(split v i)
Return two collections split from a vector with i as the index starting the second group.
Return two collections split from a vector with i as the index starting the second group.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close