Vector operations
· Mathematics · Vector · Radford Mathematics - Vectors & Matrices · Khan Academy Linear Algebra ·
TOC
Definition
Vectors are quantities that are defined by two things:
- their magnitude, and
- their direction.
A couple of examples of vectors are velocity and force.
In 2 dimensions, a Vector is described by two components:
- a horizontal component, x component
- a vertical component, y component
Properties
All perpendicular vectors are orthogonal but not vice versa
A zero vector is orthogonal to anything including itself
The (non zero) vectors are collinear if one of them is scalar multiple of the other (same Vector of different length), the angle between collinear vectors is zero
ijk vector representation
as a sum of its components multiplied by the corresponding unit vectors
Vector length
Vector length is equal to the square root of the sums of its squared coordinates
and also follows that $$\color{orange}\lVert\vec a\rVert^2=\vec a\cdot\vec a$$
Vector operations
Vector addition
Vector subtraction
The resulting vector
Vector to scalar multiplication (vector result)
Dot product (scalar product)
Defined for any dimensionality
properties
- commutative property:
- distributive property:
- associative property:
and are orthogonal (and perpendicular if not zero) when the dot product - law of cosine:
where is the angle between and - in geometric sense the dot product gives how much of the vectors are going in the same direction, or a projection (shadow) of one vector on another
Cross product (vector product)
Defined only for 3D space, order dependent
properties
, where is the angle between the vectors - triple product:
- resulting
is orthogonal to and (and perpendicular, if is not zero vectors) - #right_hand_rule:
is the index finger, is the middle finger, the thumb is the resulting
cross product to calculate the area of a
- parallelogram
Given the parallelogram with sides ofand , its area is equal to the magnitude of the cross product:
- triangle
Given a triangle whose side are defined byand , its are is given by:
The triangle's area is half of the parallelogram's area (see above)
Angle between vectors
Given that
- if
then and are collinear (if non zero vectors), the angle between them is zero, i.e. - law of cosine:
where
this means that if the vectors are collinear the fraction is = 1 and the arccos(1) = 0 - zero angle between the vectors
A line crossing 2 points
Given 2 position vectors, and parametric
the order is not important here, it can be
Vectors blend (unversal for no unit vectors)
Vector3 Slerp(Vector3 start, Vector3 end, float percent)
{
// Dot product - the cosine of the angle between 2 vectors.
float dot = Vector3.Dot(start, end);
// Clamp it to be in the range of Acos()
// This may be unnecessary, but floating point
// precision can be a fickle mistress.
Mathf.Clamp(dot, -1.0f, 1.0f);
// Acos(dot) returns the angle between start and end,
// And multiplying that by percent returns the angle between
// start and the final result.
float theta = Mathf.Acos(dot) * percent;
Vector3 RelativeVec = end - start * dot;
RelativeVec.Normalize();
// Orthonormal basis
// The final result.
return ((start*Mathf.Cos(theta)) + (RelativeVec * Mathf.Sin(theta)));
}