Same direction. Different distance.
Try “Aligned”, then move an endpoint.
- Cosine similarity
- Euclidean distance
- Lengths |A| / |B|
- Dot product A · B
Coordinates −5 to 5 in steps of ¼. Invalid entries restore the previous value.
The URL preserves both vectors.
Distance notices scale. Cosine notices direction.
A vector combines a direction with a magnitude. Euclidean distance asks how far apart two endpoints lie, in the coordinates of the data. If one arrow extends twice as far along the same ray, that distance grows—even though the direction is unchanged.
Cosine similarity divides the dot product by both vector lengths. That normalization removes positive scale: vectors pointing along the same ray have similarity 1, regardless of their nonzero lengths. Opposite directions have similarity −1. A right angle gives 0.
Expand the equations and conventions
For A = (a₁, a₂) and B = (b₁, b₂), distance is measured in data units, independently of the canvas size.
A zero vector has no direction. Its cosine similarity is undefined, not zero. Euclidean distance still exists: from (0, 0) to (3, 1), it is √10.
The implementation uses binary floating-point arithmetic, scales each vector by its largest absolute component before normalizing and taking the directional dot product, and clamps only the final cosine to [−1, 1] to contain rounding overshoot. Independent numerical checks use a 10⁻¹² relative and absolute tolerance. Readouts show three decimals; downloads retain computed precision. Outside the UI’s quarter-step domain, subnormal norms, distances and dot products can round or underflow according to IEEE floating-point rules; scaling preserves the directional cosine even at the smallest representable nonzero inputs.
One geometry is not a universal notion of similarity.
The two measures answer different questions. Cosine ignores positive changes of magnitude; Euclidean distance does not. Neither choice is automatically right for measurements with different units, learned embeddings or scientific data. This two-dimensional construction explains the definitions, without making an empirical claim about any application.
Inspect this article’s calculation source. The plot uses Cartesian y upward and a fixed −6 to 6 viewing window; controls restrict endpoints to −5 to 5.