Vectors have direction and magnitude. Number of components in a vector corresponds to number of dimensions. Scalar can be treated as speed or distance, and vector as velocity or offset with direction. Depending on requirements, vector can be written as row-vector or as column-vector (for example, for proper matrix multiplication):
Length (magnitude) of the vector:
Normalized vector (vector with lenght equal to 1, unit vector):
Magnitude of difference between vectors:
Dot product of vectors
Dot (inner) product of vectors is one of the most usefull and used operations in computer graphics. It is equal to sum of products of corresponding components of the vectors. Result is scalar value:
Dot product can be interpreted as cosine of angle between two vectors, or as projection of one vector on another. These interpretations are very related. Lets look on vectors a and b:
Cosine of angle between vectors and angle are calculated as:
Length of projection of vector a on vector b and projected vector e are equal to:
Properties of dot product:
- dot product has higher priority than addition and substraction
Cross product of vectors
Cross product is another usefull operation in computer graphics. It's only defined for 3-dimensional space. Result of cross product of two vectors is vector that is perpendicular to them. This property is used for calculation of normals, orthogonalization of vectors, etc. Lets look at vectors a and b:
Vector c is equal to:
Vectors a and b don't have to be perpendicular. Magnitude of vector c is equal to area of parallelogram S that is formed by vectors a and b. If vectors a and b are unit vectors, then magnitude of c will be equal to sine of angle between vectors a and b:
Direction of vector c depends on order of vectors in cross product. For example, in right-handed coordinate system, direction of vector c can be determined by right-hand rule. If index finger points in direction of vector a and middle finger in direction of vector b, then thumb will determine direction of vector c. For left-handed coordinate system you can use your left-hand rule. If the order of vectors in cross product is changed, then vector c will point in opposite direction.
Cross product has higher priority than addition, substraction and dot product.
Other properties of cross product:
Scalar triple product of vectors
Triple product of vectors is equal to volume of parallelepiped that is formed by vectors a, b and c:
Also, triple product is equal to determinant of a matrix that is formed form vectors a, b and c:
Properties of triple product:
- If two vectors (of a, b or c) are parallel, then result is equal to 0.
- If vectors a, b and c lie on same plane, then result is equal to 0.