Compare commits

..

No commits in common. "35e7819818ed0da3e0ef466ecc836eb4a221ad78" and "4208597ed3e6eb7d7cf7d48f03d18594ec033588" have entirely different histories.

3 changed files with 20 additions and 40 deletions

30
gyro.py
View File

@ -1,61 +1,52 @@
from numba import jit
try:
from numpy import complex256
except ImportError:
from numpy import complex128 as complex256
from cmath import sqrt
from math import tanh, atanh
from lines import cLineIntersection
@jit
def ZeroCheck(cN):
if cN == complex(0,0):
return complex(1,0)
if cN == complex256(complex(0,0)):
return complex256(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,
@ -63,22 +54,19 @@ 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 = complex(cPos)
self.cRot = complex(cRot)
self.cPos = complex256(cPos)
self.cRot = complex256(cRot)
self.normalize()
def __add__(gA, gB):

View File

@ -1,20 +1,14 @@
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)

22
main.py
View File

@ -1,9 +1,13 @@
#!/usr/bin/env python3
from numba import jit
try:
from numpy import complex256
except ImportError:
from numpy import complex128 as complex256
print("Warning! Cannot use full precision!")
from time import time_ns, sleep
from cmath import exp, pi
from math import acos, copysign
from math import acos
import pygame
import pygame.freetype
from os import makedirs
@ -14,7 +18,7 @@ from levels import *
def deg2rad(rA): return rA/180*PI
I = complex(0,1)
I = complex256(complex(0,1))
WHITE = (255,255,255)
BLACK = (0,0,0)
OFFSET = 0.015625
@ -23,9 +27,8 @@ ROT = cNorm(exp(deg2rad(2)*I))
IROT = 1/ROT
F = 5 * 10**7
F_ = 10**9
bCap = True
gOrigin = GyroVector(0,1)
gOrigin = GyroVector(complex256(0),1)
SKY = (127,127,255)
GROUND = (102, 51, 0)
@ -83,7 +86,7 @@ def renderDebugInfo(gPlayer, clock, fontSize = 18):
fps_surf = font.render("FPS: " + str(int(clock.get_fps())), font_fg, font_bg)[0]
cPos_surf = font.render("cPos: " + str(gPlayer.cPos), font_fg, font_bg)[0]
cRot_surf = font.render("cRot: " + str(copysign(acos(gPlayer.cRot.real),gPlayer.cRot.imag) / pi * 180), font_fg, font_bg)[0]
cRot_surf = font.render("cRot: " + str(acos(gPlayer.cRot.real) / pi * 180), font_fg, font_bg)[0]
return fps_surf, cPos_surf, cRot_surf
@ -129,9 +132,6 @@ def mainLoop():
gPlayer.cRot *= -1
if event.key == pygame.K_F3:
debugInfo = not debugInfo
if event.key == pygame.K_F1:
global bCap
bCap = not bCap
if event.key == pygame.K_F2:
if (len(wall_buffer) == 1):
wall_buffer.append(gPlayer.cPos)
@ -184,9 +184,7 @@ def mainLoop():
pygame.draw.rect(display, WHITE, (c.real * 100 + 95, (c.imag * 100 + 195), 10, 10))
pygame.display.update()
if bCap:
clock.tick(60)
else:
clock.tick()
return True