blob: 221ffb237e2239d7109f0440c61933b83c4a8e12 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
import type { Coord2D } from '../interfaces';
/**
* ([[cos(θ), -sin(θ),]) ([x,)
* ([sin(θ), cos(θ)] ]) ( y])
*/
export const rotateVector = (vector: Coord2D, theta: number): Coord2D => {
const rads = (theta * Math.PI) / 180;
const [cos, sin] = [Math.cos(rads), Math.sin(rads)];
return {
x: vector.x * cos - vector.y * sin,
y: vector.x * sin + vector.y * cos
};
};
|