-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvecmath.py
More file actions
58 lines (47 loc) · 950 Bytes
/
Copy pathvecmath.py
File metadata and controls
58 lines (47 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# coding: utf-8
import math
import numpy as np
def normalize(v):
# return v / np.sqrt((v**2).sum())
norm = np.linalg.norm(v)
if norm == 0:
return v
return v/norm
def angle(v1, v2):
return math.acos(np.dot(v1,v2) / (np.linalg.norm(v1) * np.linalg.norm(v2)))
def saturate(x):
if x < 0:
return 0
elif x > 1:
return 1
return x
def clamp(x,a,b):
if x < a:
return a
elif x > b:
return b
return x
def recip(x):
return 1/x
def mix(a, b, t):
return a*(1-t) + b*t
def step(edge, x):
if x < edge:
return 0
else:
return 1
def smoothstep(a, b, t):
if a >= b:
return 0
else:
x = saturate((t-a)/(b-a))
return x*x*(3-2*t)
def sign(x):
if x < 0.0:
return -1
else:
return 1
def zerocheck(x):
return max(x, np.finfo(float).eps)
def safe_pow(x,y):
return pow(zerocheck(x), y)