Sunday, January 13, 2019

Vector Math

Vector Addition
  • Can be imagined as chaining vectors
  • Vector C points to the position that vector A points to after being displaced by vector B

2D: Vector C = (Vector A.x + Vector B.x, Vector A.y + Vector B.y)
3D: Vector C = (Vector A.x + Vector B.x, Vector A.y + Vector B.y, Vector A.z + Vector B.z)

Vector Subtraction
  • Can be seen as adding a negative vector

2D: Vector C = (Vector A.x - Vector B.x, Vector A.y - Vector B.y)
3D: Vector C = (Vector A.x - Vector B.x, Vector A.y - Vector B.y, Vector A.z - Vector B.z)

Vector Scaling
  • Multiply each component of a vector by a scalar value
  • Scaling only affect the length and not the direction

2D: Vector B = (Vector A.x * i, Vector A.y * i)
3D: Vector B = (Vector A.x * i, Vector A.y * i, Vector A.z * i)

Vector Division
  • Same as vector scaling but you divide each component by a divisor

2D: Vector B = (Vector A.x / i, Vector A.y / i)
3D: Vector B = (Vector A.x / i, Vector A.y / i, Vector A.z / i)

Vector Length
  • Calculates the magnitude of the vector
2D: Length = square root(Vector A.x^2 + Vector A.y^2)
3D: Length = square root (Vector A.x^2 + Vector A.y^2 + Vector A.z^2)

Unit Vector
  • Is any vector with a length of 1
  • Also known as normalisation
  • Can be calculated by dividing each component by the vectors length
2D: Unit Vector = (Vector A.x / ||Vector A||, Vector A.y / ||Vector A||)
3D: Unit Vector = (Vector A.x / ||Vector A||, Vector A.y / ||Vector A||, Vector A.z / ||Vector A||)

No comments:

Post a Comment