33 lines
944 B
Python
33 lines
944 B
Python
#!/usr/bin/env python3
|
|
"""Regression check for the test9/test10 fake-impulse bug."""
|
|
import math
|
|
|
|
|
|
def qx(deg):
|
|
a=math.radians(deg)/2
|
|
return (math.cos(a),math.sin(a),0.0,0.0)
|
|
|
|
def conj(q):
|
|
w,x,y,z=q; return (w,-x,-y,-z)
|
|
|
|
def mul(a,b):
|
|
aw,ax,ay,az=a; bw,bx,by,bz=b
|
|
return (aw*bw-ax*bx-ay*by-az*bz,
|
|
aw*bx+ax*bw+ay*bz-az*by,
|
|
aw*by-ax*bz+ay*bw+az*bx,
|
|
aw*bz+ax*by-ay*bx+az*bw)
|
|
|
|
def rotate(q,v):
|
|
r=mul(mul(q,(0.0,*v)),conj(q)); return r[1:]
|
|
|
|
def invrotate(q,v): return rotate(conj(q),v)
|
|
def close(a,b,e=1e-9): return all(abs(x-y)<e for x,y in zip(a,b))
|
|
|
|
local=(0.17,0.42,-0.08)
|
|
for deg in (0,20,45,90,180):
|
|
world=rotate(qx(deg),local)
|
|
recovered=invrotate(qx(deg),world)
|
|
assert close(recovered,local)
|
|
print(f"X {deg:3d}: local={local} -> world={world} -> local={recovered}")
|
|
print('OK: changing ship orientation changes world representation without changing local velocity')
|