fromV3 (1,2,3) 1 == (1,2,3,1)map (\x -> x^2) (1,2,3,4) == (1,4,9,16)map2 (<) (2,1,4,2) (3,2,1,6) == (True, True, False, True)foldl (\elem acc -> acc + elem^2) 0 (2,4,1,2) == 25foldr (::) [] (1,2,3,5) == [1,2,3,5]v + w
add (2,4,1,-2) (3,-6,2,1) == (5,-2,3,-1)v - w
sub (4,6,1,2) (3,-1,-4,4) == (1,7,5,-2)-v
negate (2,-1,5,1) == (-2,1,-5,-1)a*v
scale (3/2) (4,2,6,10) == (6,3,9,15)v/a
divideBy (3/2) (3,12,6,9) == (2,8,4,6)v dot w
The dot product of two vectors. Also called scalar product or inner product.
It links the length and angle of two vectors.
v dot w = |v|*|w|*cos(phi)
dot (1,2,2,3) (3,3,2,2) == 1*3 + 2*3 + 2*2 + 3*2 == 19The length of a vector. Also known as magnitude or norm.
|v| = sqrt(v dot v)
length (2,4,1,2) == sqrt (2^2+4^2+1^2+2^2) == 5The squared length. This is cheaper to calculate, so if you only need to compare lengths you can use this instead of the length.
|v|^2 = v dot w
lengthSquared (3,4,1,2) == 3^2+4^2+1^2+2^2 == 30Normalizes a vector. This will give you a unit vector (e.g. with length 1) in the same direction as v.
v/|v|
normalize (2,4,1,2) == (2/5,4/5,1/5,2/5)A unit vector pointing from v to w
(w - v)/|w - v|
directionFromTo (5,1,2,4) (7,5,3,6) == (2/5,4/5,1/5,2/5)Calculates the distance from v to w.
|v - w| = |w - v|
distance (7,5,3,6) (5,1,2,4) == 5The squared distance. This is slightly faster.
|v - w|^2
distanceSquared (3,0,2,1) (0,2,4,1) == 17The angle between two vectors. The angle is in radians.
acos((v dot w)/(|v|*|w|))
angle (-1,-1,2,0) (2,2,2,0) == pi/2 -- or 90°