fromV2 (1,2) 3 == (1,2,3)map sqrt (1,4,9) == (1,2,3)map2 (/) (4,9,12) (2,3,4) == (2,3,3)foldl (*) 1 (2,4,1) == 8foldr max 0 (1,12,-5) == 12v + w
add (2,4,1) (3,-6,2) == (5,-2,3)v - w
sub (4,6,1) (3,-1,-4) == (1,7,5)-v
negate (2,-1,5) == (-2,1,-5)a*v
scale (1/2) (4,2,6) == (2,1,3)v/a
divideBy (1/2) (2,1,3) == (4,2,6)NaN/infinity warning: if a = 0
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,2) == 1*3 + 2*3 + 2*2 == 13v cross w
The cross product of two vectors. Also called vector product.
v cross w is a vector that is perpendicular to both v and w
and therefore normal to the plane containing them.
The length of v cross w is equal to the area of the parallelogram spanned by v and w.
|v cross w| = |v|*|w|*sin(phi)
cross (2,1,3) (4,5,-3) == (1*(-3) - 3*5, 3*4 - 2*(-3), 2*5 - 1*4) == (-18, 18, 6)The length of a vector. Also known as magnitude or norm.
|v| = sqrt(v dot v)
length (4,2,4) == sqrt (4^2+2^2+4^2) == 6The 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) == 3^2+4^2+1^2 == 26Normalizes a vector. This will give you a unit vector (e.g. with length 1) in the same direction as v.
v/|v|
normalize (4,2,4) == (2/3,1/3,2/3)NaN warning: if v = 0
A unit vector pointing from v to w
(w - v)/|w - v|
directionFromTo (5,1,2) (9,3,6) == (2/3,1/3,2/3)NaN warning: if v = w
Calculates the distance from v to w.
|v - w| = |w - v|
distance (2,0,4) (0,4,0) == 6The squared distance. This is slightly faster.
|v - w|^2
distanceSquared (3,0,2) (0,4,1) == 26The angle between two vectors. The angle is in radians.
acos((v dot w)/(|v|*|w|))
angle (-1,-1,2) (2,2,2) == pi/2 -- or 90°NaN warning: if v = 0 or w = 0
The projection of v onto w.
(v dot w)/|w| * w/|w|
project (2,1,0) (4,0,0) == (2,0,0)NaN warning: if w = 0
The rejection of v onto w. This is always perpendicular to the projection.
v - (project v w)
reject (2,1,0) (4,0,0) == (0,1,0)NaN warning: if w = 0