geom-demo/geom/math.py
2020-11-13 18:46:31 +04:00

29 lines
515 B
Python

import math
ZERO = (0, 0)
def dot(x1, y1, x2, y2):
return (x1 * x2) + (y1 * y2)
def length(x, y):
return math.sqrt((x * x) + (y * y))
def normalize(x, y):
_len = length(x, y)
return x / _len, y / _len
def scale(x, y, factor):
return x * factor, y * factor
def add(x1, y1, x2, y2):
return x1 + x2, y1 + y2
def sub(x1, y1, x2, y2):
return x1 - x2, y1 - y2
def vmin(x1, y1, x2, y2):
return min(x1, x2), min(y1, y2)
def vmax(x1, y1, x2, y2):
return max(x1, x2), max(y1, y2)