Copy folder

This commit is contained in:
Andras Schmelczer 2022-09-26 12:30:36 +02:00
commit f40d182e88
7 changed files with 343 additions and 0 deletions

13
js/vec2.js Normal file
View file

@ -0,0 +1,13 @@
const magnitude = ([x, y]) => Math.sqrt(x * x + y * y);
const add = ([x1, y1], [x2, y2]) => [x1 + x2, y1 + y2];
const subtract = ([x1, y1], [x2, y2]) => [x1 - x2, y1 - y2];
const limit = ([x, y], maxMagnitude) => {
const m = magnitude([x, y]);
if (m <= maxMagnitude) return [x, y];
const scalingFactor = maxMagnitude / m;
return [x * scalingFactor, y * scalingFactor];
};