Work · Interactive explainer · Synthetic

Vector Geometry

Cosine similarity and Euclidean distance answer different questions. Change two vectors to see what direction and magnitude each measure keeps.

Lucian Murgu · Synthetic 2D geometry · No empirical results

Same direction. Different distance.

Try “Aligned”, then move an endpoint.

The vector coordinates and metrics appear in the controls and numerical readout.
Arrows start at the origin. The dashed line joins their tips. Drag either endpoint, or edit its coordinates. One grid interval = one unit.
Cosine similarity
—
Euclidean distance
—
Lengths |A| / |B|
—
Dot product A · B
—
A First vector
B Second vector

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.

d=(a1−b1)2+(a2−b2)2
cos⁡θ=A·B‖A‖‖B‖

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.

Scope & limitations

  • Two-dimensional dimensionless vectors; no claims about embedding quality or any real dataset.
  • Cosine is undefined for zero vectors. UI inputs are bounded to −5…5 in steps of 0.25.
  • Three-decimal labels are rounded; binary floating-point results are independently checked with absolute/relative tolerance 1e-12.