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.
(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.
(chebyshev x y)Chebyshev (maximum metric) distance
Chebyshev (maximum metric) distance
(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.
(extrude coll dir steps)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.
(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`
(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`.
(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.(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.
(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)`
(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
(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.
(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`.
(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`.
(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`.
(vnorm v)Normalize a vector to be length=1
Normalize a vector to be length=1
(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.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |