Use Numba to increase performance.
This commit is contained in:
parent
359edf4742
commit
ac6330efd0
30
gyro.py
30
gyro.py
@ -1,52 +1,61 @@
|
||||
try:
|
||||
from numpy import complex256
|
||||
except ImportError:
|
||||
from numpy import complex128 as complex256
|
||||
|
||||
from numba import jit
|
||||
from cmath import sqrt
|
||||
from math import tanh, atanh
|
||||
from lines import cLineIntersection
|
||||
|
||||
@jit
|
||||
def ZeroCheck(cN):
|
||||
if cN == complex256(complex(0,0)):
|
||||
return complex256(complex(1,0))
|
||||
if cN == complex(0,0):
|
||||
return complex(1,0)
|
||||
else:
|
||||
return cN
|
||||
|
||||
@jit
|
||||
def c_tr(cN):
|
||||
return cN.real, cN.imag
|
||||
|
||||
@jit
|
||||
def cNorm(cN):
|
||||
return ZeroCheck(cN)/abs(ZeroCheck(cN))
|
||||
|
||||
@jit
|
||||
def cDot(cA, cB):
|
||||
return (cA * cB.conjugate()).real
|
||||
|
||||
@jit
|
||||
def cDist(cA, cB):
|
||||
return abs(cA-cB)
|
||||
|
||||
@jit
|
||||
def MobiusInt(cA,cB,cC,cD): # Bruh
|
||||
return Klein2Poincare(cLineIntersection(Poincare2Klein(cA),Poincare2Klein(cB),Poincare2Klein(cC),Poincare2Klein(cD)))
|
||||
|
||||
@jit
|
||||
def MobiusAdd(cA, cB):
|
||||
return (cA + cB) / (1 + cA.conjugate() * cB)
|
||||
|
||||
@jit
|
||||
def MobiusGyr(cA, cB):
|
||||
return (1 + cA * cB.conjugate()) / (1 + cA.conjugate() * cB)
|
||||
|
||||
@jit
|
||||
def MobiusAddGyr(cA, cB):
|
||||
return MobiusAdd(cA, cB), MobiusGyr(cA, cB)
|
||||
|
||||
@jit
|
||||
def MobiusScalar(cA, rT):
|
||||
m = abs(cA)
|
||||
return tanh(rT * atanh(m)) * cA / m
|
||||
|
||||
@jit
|
||||
def MobiusCoadd(cA,cB):
|
||||
return MobiusAdd(cA, (MobiusGyr(cA,-cB) * cB))
|
||||
|
||||
@jit
|
||||
def MobiusCosub(cA,cB):
|
||||
return MobiusAdd(cA, -(MobiusGyr(cA,cB) * cB))
|
||||
|
||||
@jit
|
||||
def MobiusLine(cA,cB,rT):
|
||||
return MobiusAdd(
|
||||
cA,
|
||||
@ -54,19 +63,22 @@ def MobiusLine(cA,cB,rT):
|
||||
MobiusAdd(-cA,cB),
|
||||
rT))
|
||||
|
||||
@jit
|
||||
def MobiusDist(cA,cB):
|
||||
return abs(MobiusAdd(-cB,cA))
|
||||
|
||||
@jit
|
||||
def Poincare2Klein(cN):
|
||||
return 2*cN / (1 + cDot(cN,cN))
|
||||
|
||||
@jit
|
||||
def Klein2Poincare(cN):
|
||||
return (1-sqrt(1-cDot(cN,cN)))*cN/cDot(cN,cN)
|
||||
|
||||
class GyroVector:
|
||||
def __init__(self, cPos, cRot):
|
||||
self.cPos = complex256(cPos)
|
||||
self.cRot = complex256(cRot)
|
||||
self.cPos = complex(cPos)
|
||||
self.cRot = complex(cRot)
|
||||
self.normalize()
|
||||
|
||||
def __add__(gA, gB):
|
||||
|
6
lines.py
6
lines.py
@ -1,14 +1,20 @@
|
||||
from numba import jit
|
||||
|
||||
@jit
|
||||
def LineIntersection(rX1,rY1,rX2,rY2,rX3,rY3,rX4,rY4):
|
||||
rX = ( (rX1*rY2-rY1*rX2)*(rX3-rX4)-(rX1-rX2)*(rX3*rY4-rY3*rX4) ) / ( (rX1-rX2)*(rY3-rY4)-(rY1-rY2)*(rX3-rX4) )
|
||||
rY = ( (rX1*rY2-rY1*rX2)*(rY3-rY4)-(rY1-rY2)*(rX3*rY4-rY3*rX4) ) / ( (rX1-rX2)*(rY3-rY4)-(rY1-rY2)*(rX3-rX4) )
|
||||
return (rX, rY)
|
||||
|
||||
@jit
|
||||
def cLineIntersection(cA0, cA1, cB0, cB1):
|
||||
rX, rY = LineIntersection(cA0.real, cA0.imag, cA1.real, cA1.imag, cB0.real, cB0.imag, cB1.real, cB1.imag)
|
||||
return complex(rX, rY)
|
||||
|
||||
@jit
|
||||
def Between(rA,rB,rN):
|
||||
return (rA < rN and rN < rB) or (rB < rN and rN < rA)
|
||||
|
||||
@jit
|
||||
def cBetween(cA,cB,cN):
|
||||
return Between(cA.real,cB.real,cN.real) and Between(cA.imag,cB.imag,cN.imag)
|
||||
|
10
main.py
10
main.py
@ -1,9 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
try:
|
||||
from numpy import complex256
|
||||
except ImportError:
|
||||
from numpy import complex128 as complex256
|
||||
print("Warning! Cannot use full precision!")
|
||||
from numba import jit
|
||||
|
||||
from time import time_ns, sleep
|
||||
from cmath import exp, pi
|
||||
@ -15,7 +11,7 @@ from lines import *
|
||||
|
||||
def deg2rad(rA): return rA/180*PI
|
||||
|
||||
I = complex256(complex(0,1))
|
||||
I = complex(0,1)
|
||||
WHITE = (255,255,255)
|
||||
BLACK = (0,0,0)
|
||||
OFFSET = 0.015625
|
||||
@ -25,7 +21,7 @@ IROT = 1/ROT
|
||||
F = 5 * 10**7
|
||||
F_ = 10**9
|
||||
|
||||
gOrigin = GyroVector(complex256(0),1)
|
||||
gOrigin = GyroVector(0,1)
|
||||
|
||||
SKY = (127,127,255)
|
||||
GROUND = (102, 51, 0)
|
||||
|
Loading…
Reference in New Issue
Block a user