Liking cljdoc? Tell your friends :D

lambdaisland.witchcraft.matrix

Vector/Matrix math

A vector in this context can be anything that implements [[lambdaisland.witchcraft/with-xyz]]: a Clojure vector ([x y z]), a Clojure map ({:x .. :y .. :z ..}), or a Glowstone Location or Vector. You get the type back that you put in.

A matrix is a vector of vectors (regular Clojure vectors) and can be 3x3 (linear) or 4x4 (affine/homogenous).

This code is not optimized for speed, it is fine for generating and manipulating minecraft structures, not for heavy number crunching.

Vector/Matrix math

A vector in this context can be anything that
implements [[lambdaisland.witchcraft/with-xyz]]: a Clojure vector (`[x y z]`),
a Clojure map (`{:x .. :y .. :z ..}`), or a Glowstone `Location` or `Vector`.
You get the type back that you put in.

A matrix is a vector of vectors (regular Clojure vectors) and can be
3x3 (linear) or 4x4 (affine/homogenous).

This code is not optimized for speed, it is fine for generating and
manipulating minecraft structures, not for heavy number crunching.

raw docstring

centerclj

(center coll)

The center point of a collection of points, simply takes the average in each dimension.

The center point of a collection of points, simply takes the average in each
dimension.
sourceraw docstring

chebyshevclj

(chebyshev x y)

Chebyshev (maximum metric) distance

Chebyshev (maximum metric) distance
sourceraw docstring

cross-productclj

(cross-product a b)
source

dot-productclj

(dot-product a b)

Vector dot product

Arguments can be Clojure maps (:x/:y/:z), vectors, or Glowstone Location or Vector instances. Returns a number.

Vector dot product

Arguments can be Clojure maps (:x/:y/:z), vectors, or Glowstone Location or
Vector instances. Returns a number.
sourceraw docstring

extrudeclj

(extrude dir steps coll)

Extrude a shape in a given direction, takes a collection of locations/blocks, a direction vector, and a number of times to apply the direction vector.

Extrude a shape in a given direction, takes a collection of locations/blocks, a
direction vector, and a number of times to apply the direction vector.
sourceraw docstring

identity-matrixclj

(identity-matrix degree)

Return a degree x degree matrix with all elements on the diagonal 1 and all others 0

Return a `degree x degree` matrix with all elements on the diagonal `1` and all
others `0`
sourceraw docstring

m*clj

(m* m s)

Multiply a matrix with a scalar

Multiply a matrix with a scalar
sourceraw docstring

m*mclj

(m*m m1 m2)
(m*m m1 m2 & rest)

Multiply matrices

Multiply matrices
sourceraw docstring

m*vclj

(m*v m v)

Multiply a matrix (vector of vectors) with a vector

m is a Clojure vector of vectors, 3x3 (linear) or 4x4 (affine). v can be a Clojure map (:x/:y/:z), vector ([x y z]), or Glowstone Location or Vector instance. Returns the same type as v.

Multiply a matrix (vector of vectors) with a vector

`m` is a Clojure vector of vectors, 3x3 (linear) or 4x4 (affine). `v` can be a
Clojure map (`:x/:y/:z`), vector (`[x y z]`), or Glowstone Location or Vector
instance. Returns the same type as `v`.
sourceraw docstring

manhattenclj

(manhatten x y)

Manhatten distance

Manhatten distance
sourceraw docstring

mirror-matrixclj

(mirror-matrix mappings)

Matrix which mirrors points, mappings is a map of one or more of :x/:y/:z to :x/:-x/:y/:-y/:z/:-z. E.g. a mapping of {:x :-x} means that the x value gets flipped, in other words it's a mirroring around the z=0 plane. {:x :z, :z :x} means that the x and z values get swapped, i.e. a mirroring around the x=z plane.

Matrix which mirrors points, mappings is a map of one or more of `:x/:y/:z` to
`:x/:-x/:y/:-y/:z/:-z`. E.g. a mapping of `{:x :-x}` means that the x value
gets flipped, in other words it's a mirroring around the `z=0` plane.
`{:x :z, :z :x}` means that the `x` and `z` values get swapped, i.e. a
mirroring around the `x=z` plane.
sourceraw docstring

rotateclj

(rotate rad dim1 dim2 coll)

Rotate a shape around its center (average of all block locations), given an angle in radians, and the two dimensions (as keywords, :x/:y/:z) that form the plane within which to rotate.

Rotate a shape around its center (average of all block locations), given an
angle in radians, and the two dimensions (as keywords, `:x`/`:y`/`:z`) that
form the plane within which to rotate.
sourceraw docstring

rotation-matrixclj

(rotation-matrix rad dim1 dim2)

Matrix which rotates around the origin, takes the rotation in radians, and the dimensions that form the plane in which the rotation is performed, e.g. (rotation-matrix Math/PI :x :z)

Matrix which rotates around the origin, takes the rotation in radians, and the
dimensions that form the plane in which the rotation is performed,
e.g. `(rotation-matrix Math/PI :x :z)`
sourceraw docstring

transformclj

(transform coll m)
(transform coll m & rest)

Transform a collection by applying a matrix to each element

Transform a collection by applying a matrix to each element
sourceraw docstring

translateclj

(translate offset coll)

Move all locations by a given offset

Move all locations by a given offset
sourceraw docstring

translation-matrixclj

(translation-matrix v)

Returns an affine transformation matrix that moves a location by a fixed amount in each dimension.

Returns an affine transformation matrix that moves a location by a fixed amount
in each dimension.
sourceraw docstring

transposeclj

(transpose m)

Transpose a matrix

Transpose a matrix
sourceraw docstring

v*clj

(v* v s)

Multiply a vector with a scalar

v can be a Clojure map (:x/:y/:z), vector ([x y z]), or Glowstone Location or Vector instance. Returns the same type as v.

Multiply a vector with a scalar

`v` can be a
Clojure map (`:x/:y/:z`), vector (`[x y z]`), or Glowstone Location or Vector
instance. Returns the same type as `v`.
sourceraw docstring

v+clj

(v+ a b)

Vector addition

Arguments can be Clojure maps (:x/:y/:z), vectors, or Glowstone Location or Vector instances. The return type is the type of a.

Vector addition

Arguments can be Clojure maps (:x/:y/:z), vectors, or Glowstone Location or
Vector instances. The return type is the type of `a`.
sourceraw docstring

v-clj

(v- a)
(v- a b)

Vector subtraction

Arguments can be Clojure maps (:x/:y/:z), vectors, or Glowstone Location or Vector instances. The return type is the type of a.

Vector subtraction

Arguments can be Clojure maps (:x/:y/:z), vectors, or Glowstone Location or
Vector instances. The return type is the type of `a`.
sourceraw docstring

vlengthclj

(vlength v)

Vector length

Vector length
sourceraw docstring

vnormclj

(vnorm v)

Normalize a vector to be length=1

Normalize a vector to be length=1
sourceraw docstring

with-originclj

(with-origin matrix origin)

Takes an affine transformation matrix, and an origin coordinate, and returns a matrix which performs the same trasnformation, but around the new origin. Use this to change the "anchor" around which e.g. a rotation happens, which by default is otherwise the [0 0 0] origin coordinate.

Takes an affine transformation matrix, and an origin coordinate, and returns a
matrix which performs the same trasnformation, but around the new origin. Use
this to change the "anchor" around which e.g. a rotation happens, which by
default is otherwise the `[0 0 0]` origin coordinate.
sourceraw docstring

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

× close