Skip to main content

dotprod

Discworld driver help

dotprod

Name

dotprod - return the dot product between two vectors

Synopsis

float dotprod( vector v1, vector v2 );

Description

"vector" is not actually a type in LPC. It is used here to represent an array of ints and/or floats.

dotprod( v1, v2 ) returns the dot product of vectors `v1' and `v2'. This is defined as the product of the norms of the two vectors and the cosine of the angle between them; or equivalently as the sum of v1[i] * v2[i], for each coordinate of the vector.

`v1' and `v2' must be of the same size, otherwise a runtime is produced.

By its definition, dotprod( v, v ) is equal to the norm of v squared.

See also

vectors, norm(), distance(), angle()