Dot Product in 2D with Python

Talking about dot products in linear algebra can be really a subject of hours, but long story short this is probably the minimal knowledge you can live with:

  • The dot product (inner product) is an operation on 2 vectors that return a scalar.
    E.g., given 2 vectors u and v, have their result, v)  to be a real number.
  • The dot product works on vectors in 2D, 3D or other dimensions.
  • The dot product is measuring “how aligned” 2 vectors are.
    • In 2D space, parallel vectors, pointing in the same direction, have dot products of 1.
    • In 2D space, parallel vectors, pointing in the opposite directions, have dot products of -1.
    • Perpendicular vectors, forming a 90-degree angle, always produce a dot product of 0 due to the cosine of the angle being 0.
    • For vectors with arbitrary angles between them, the dot product varies according to the cosine of the angle formed, resulting in values other than 0, 1, or -1.

Pretty much that is just the top of the iceberg, but it is good to illustrate this a bit:

Returns the following, where it is obvious which vectors are perpendicular:

Vector 2 and Vector 1 are perpendicular, with degree between them equalling 90 and a dot product of 0.

Thank you for your interest and enjoy the linear algebra and your day!

Tagged with: , ,