dot(): The Dot Product of Vectors
dot() calculates an inner, or dot, product. For vectors it multiplies corresponding entries and adds the results. The dot product connects direction and magnitude, making it fundamental in geometry, projections, graphics, and statistics.
Angle and projection
For normalized vectors, dot(a, b) equals the cosine of the angle between them. A positive result means similar direction, zero means perpendicular, and a negative result means opposite direction. Use acos() to turn a normalized dot product into an angle, and norm() to find lengths for normalization.
Vectors must have compatible lengths; matrix products additionally require matching inner dimensions. Do not confuse dot with dotMultiply(), which returns element-wise products, or multiply(), which performs general multiplication.
Practical checks
Use size() when dimensions come from data. In floating-point work, a near-zero dot product indicates approximate perpendicularity, not necessarily exact zero.