(direction-vector r)
Calculate the unit direction vector based on the rotation angle.
Calculate the unit direction vector based on the rotation angle.
(invert v)
Multiply each component of the vector by -1.
Represents a rotation of 180 degrees.
Multiply each component of the vector by -1. Represents a rotation of 180 degrees.
(magnitude v)
Calculate the length of a vector.
Calculate the length of a vector.
(normalize v)
Calculate the unit vector of a given vector.
We calculate the reciprocal of the magnitude of the vector and multiply the components by this factor to avoid multiple division operations.
Calculate the unit vector of a given vector. We calculate the reciprocal of the magnitude of the vector and multiply the components by this factor to avoid multiple division operations.
(orthogonals [x y])
Calculate the two orthogonal vectors to a given 2D vector.
Y axis is inverted so this returns [90-degrees-right-vector 90-degrees-left-vector]
Calculate the two orthogonal vectors to a given 2D vector. Y axis is inverted so this returns [90-degrees-right-vector 90-degrees-left-vector]
(poly-lines poly)
Construct the lines that make up a polygon from its points.
Construct the lines that make up a polygon from its points.
(ratio-pos window [x-factor y-factor])
Create an [x y]
vector position at the specified ratio
coordinates.
Create an `[x y]` vector position at the specified ratio coordinates.
(rotate-vector [x y :as v] r)
Rotate a vector about the origin by r
degrees.
Checks first for r
representing an integer number of rotations, in
with case the vector will be unchanged.
Rotate a vector about the origin by `r` degrees. Checks first for `r` representing an integer number of rotations, in with case the vector will be unchanged.
(rotation-angle [x y])
Calculate the rotation angle of a vector.
Calculate the rotation angle of a vector.
(squared-magnitude [x y z])
Sum the squares of the components of a vector.
The if
check on z
is a lot faster than doing an apply
or
reduce
across the vector.
Sum the squares of the components of a vector. The `if` check on `z` is a lot faster than doing an `apply` or `reduce` across the vector.
(unit-vector v)
Calculate the unit vector of a given vector.
Calculate the unit vector of a given vector.
(v< a b)
Determine if the magnitude of a vector a
is less than the magnitude
of vector b
.
We can just compare the component squares to avoid the costly sqrt
operations.
Determine if the magnitude of a vector `a` is less than the magnitude of vector `b`. We can just compare the component squares to avoid the costly `sqrt` operations.
(v<= a b)
Determine if the magnitude of a vector a
is less than or equal to
the magnitude of vector b
.
We can just compare the component squares to avoid the costly sqrt
operations.
Determine if the magnitude of a vector `a` is less than or equal to the magnitude of vector `b`. We can just compare the component squares to avoid the costly `sqrt` operations.
(zero-vector? v)
Predicate to check if a vector has length 0.
Predicate to check if a vector has length 0.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close