Zinggi/elm-webgl-math/1.0.4

NOTE: this package is not compatible with Elm 0.19.1

Matrix2

type alias Float2x2 =
Mat2 Float
type alias Mat2 a =
( Vec2 a, Vec2 a )

General operations

map : (a -> b) -> Mat2 a -> Mat2 b
elementsSquared = map (\x -> x^2)
map2 : (a -> b -> c) -> Mat2 a -> Mat2 b -> Mat2 c
elementWiseDivision = map2 (/)
foldl : (elem -> acc -> acc) -> acc -> Mat2 elem -> acc
foldr : (elem -> acc -> acc) -> acc -> Mat2 elem -> acc

Math

identity : Float2x2

The identity matrix.

I = |1 0|
    |0 1|


I*A = A = A*I
fromRows : Float2 -> Float2 -> Float2x2

Construct a matrix from rows.

fromRows (1,2) (3,4) == ((1,2),(3,4))
fromColumns : Float2 -> Float2 -> Float2x2

Construct a matrix from columns.

fromColumns (1,2) (3,4) == ((1,3),(2,4))
add : Float2x2 -> Float2x2 -> Float2x2

Matrix addition.

|a b|   |e f|   |a+e b+f|
|c d| + |g h| = |c+g d+h|
sub : Float2x2 -> Float2x2 -> Float2x2

Matrix subtraction.

A - B

mul : Float2x2 -> Float2x2 -> Float2x2

Matrix multiplication.

A*B

elementWiseMul : Float2x2 -> Float2x2 -> Float2x2

Element wise multiplication. Also called Hadamard product, Schur product or entrywise product.

|a b|    |e f|   |ae bf|
|c d| .* |g h| = |cg dh|
mulByConst : Float -> Float2x2 -> Float2x2

a*A Multiply a matrix by a constant

transpose : Float2x2 -> Float2x2

The transpose. Flips a matrix along it's diagonal.

|a b|T  |a c|
|c d| = |b d|
mulVector : Float2x2 -> Float2 -> Float2

Matrix-vector multiplication.

      |a b| |x|   |ax+by|
A*v = |c d|*|y| = |cx+dy|

Other

almostEqual : Float -> Float2x2 -> Float2x2 -> Bool

This checks whether |A - B| < eps.

almostEqual eps a b

This is useful for testing, see the tests of this library for how this makes testing easy.

Since any definition of a norm can be used for this, it uses the simple maxNorm

maxNorm : Float2x2 -> Float

The max norm. This is the biggest element of a matrix. Useful for fuzz testing.