Skip to content

@ue-too/math / index / sameDirection

関数: sameDirection()

sameDirection(a, b, precision): boolean

定義: index.ts:791

Checks if two vectors point in the same direction.

パラメータ

a

Point

First vector

b

Point

Second vector

precision

number = 0.001

Tolerance for comparison (defaults to 0.001)

戻り値

boolean

True if vectors have the same direction (after normalization)

Remarks

Normalizes both vectors to unit vectors and compares them. Magnitude does not matter, only direction.

typescript
const a = { x: 1, y: 0 };
const b = { x: 10, y: 0 }; // Same direction, different magnitude
sameDirection(a, b); // true

const c = { x: 1, y: 1 };
sameDirection(a, c); // false (different direction)