initial commit

This commit is contained in:
2023-11-24 14:34:44 +01:00
commit ab12333184
12 changed files with 598 additions and 0 deletions

27
vec.py Normal file
View File

@@ -0,0 +1,27 @@
from __future__ import annotations
from math import sqrt
class Vec:
def __init__(self, x: float = 0, y: float = 0) -> None:
self.x = x
self.y = y
def __add__(self, v: Vec) -> Vec:
return Vec(self.x+v.x, self.y+v.y)
def __sub__(self, v: Vec) -> Vec:
return Vec(self.x-v.x, self.y-v.y)
def __mul__(self, f: float) -> Vec:
return Vec(self.x*f, self.y*f)
def __truediv__(self, f: float) -> Vec:
return Vec(self.x/f, self.y/f)
def mag(self) -> float:
return sqrt(self.x**2 + self.y**2)
def norm(self) -> Vec:
mag = self.mag()
if mag == 0: return Vec()
return self/mag