In [1]:
from sympy import *
from galgebra.ga import Ga
from galgebra.printer import Format
Format()
import math
import sympy as sym
In [2]:
cga3d = Ga(r'e_1 e_2 e_3 e e_{0}',g='1 0 0 0 0,0 1 0 0 0,0 0 1 0 0,0 0 0 0 -1,0 0 0 -1 0')
In [3]:
cga3d.g
Out[3]:
In [4]:
e1,e2,e3,eo,eoo = cga3d.mv()
In [5]:
def pt(arg): # R^3 vector --> conformal point.
if isinstance(arg,str): # Return general 3D point
v = cga3d.mv(arg, 'vector') # General conformal vector
v = v + (v < eoo)*eo + (v < eo)*eoo # 3D part
v = eo + v + (v<v)*eoo/2
elif arg == 0:
v = eo
elif (arg < eoo) == 0: # Return point for 3D vector in arg
v = eo + arg + (arg<arg)*eoo/2
else: v = arg # arg already in conformal representation
return(v)
In [6]:
ax = sym.Symbol('a_x')
ay = sym.Symbol('a_y')
az = sym.Symbol('a_z')
a = ax*e1+ay*e2+az*e3
cx = sym.Symbol('c_x')
cy = sym.Symbol('c_y')
cz = sym.Symbol('c_z')
c = cx*e1+cy*e2+cz*e3
sx = sym.Symbol('s_x')
sy = sym.Symbol('s_y')
sz = sym.Symbol('s_z')
s = sx*e1+sy*e2+sz*e3
x = sym.Symbol('x')
nx = sy
ny = -sx
nz = 0
n = nx*e1+ny*e2+nz*e3
I = e1^e2^e3
II = e1^e2^e3^eo^eoo
A = pt(a)
C = pt(c)
S = pt(a + s)
N = pt(a + n)
m = I*(s^n)
M = pt(a + m)
In [7]:
plane_1 =((A^M^S^eoo))
plane_2 =((A^C^S^eoo))
In [8]:
EQ=(plane_1<plane_2)
E1=(plane_1<plane_1)
E2=(plane_2<plane_2)
In [9]:
from sympy.solvers import solve
import sympy as sym
from sympy import Symbol
In [10]:
EQ
Out[10]:
In [11]:
EQ.obj
Out[11]:
In [12]:
solve(EQ.obj, ax)
Out[12]:
In [13]:
solve(sym.cos(x) - EQ.obj, x)
Out[13]:
In [14]:
solve(sym.cos(x) - ax*sx, x)
Out[14]:
In [15]:
from sympy.solvers import solve
import sympy as sym
from sympy import Symbol
In [16]:
EQQ=EQ.subs({ax:10, ay: 24, az: 20,cx:10, cy: 26, cz: 20,sx:10, sy:11, sz: 20})
E1Q=E1.subs({ax:10, ay: 24, az: 20,cx:10, cy: 26, cz: 20,sx:10, sy:11, sz: 20})
E2Q=E2.subs({ax:10, ay: 24, az: 20,cx:10, cy: 26, cz: 20,sx:10, sy:11, sz: 20})
In [17]:
EQQ/(E1Q*E2Q)
Out[17]:
In [18]:
sym.acos(float(11/6862050))
Out[18]:
A rewritten version:
In [1]:
from sympy import *
from galgebra.ga import Ga
from galgebra.printer import Format
Format()
import math
import sympy as sym
In [2]:
cga3d = Ga(r'e_x e_y e_z e_{0} e_{\infty}',g='1 0 0 0 0,0 1 0 0 0,0 0 1 0 0,0 0 0 0 -1,0 0 0 -1 0')
In [3]:
e_x,e_y,e_z,e_0,e_oo = cga3d.mv()
In [4]:
e_x
Out[4]:
In [5]:
e_y
Out[5]:
In [6]:
e_z
Out[6]:
In [7]:
e_0
Out[7]:
In [8]:
e_oo
Out[8]:
In [9]:
def pt(arg): # R^3 vector --> conformal point.
if isinstance(arg,str): # Return general 3D point
v = cga3d.mv(arg, 'vector') # General conformal vector
v = v + (v < e_oo)*e_0 + (v < e_0)*e_oo # 3D part
v = e_0 + v + (v<v)*e_oo/2
elif arg == 0:
v = e_0
elif (arg < e_oo) == 0: # Return point for 3D vector in arg
v = e_0 + arg + (arg<arg)*e_oo/2
else: v = arg # arg already in conformal representation
return(v)
In [10]:
def point(v_name, v_x=None, v_y=None, v_z=None):
v_x_name = '%s_x' % v_name
v_y_name = '%s_y' % v_name
v_z_name = '%s_z' % v_name
v_x = sym.Symbol(v_x_name) if v_x is None else v_x
v_y = sym.Symbol(v_y_name) if v_y is None else v_y
v_z = sym.Symbol(v_z_name) if v_z is None else v_z
v = v_x * e_x + v_y * e_y + v_z * e_z
return {v_name: v, v_x_name: v_x, v_y_name: v_y, v_z_name: v_z}
In [11]:
def vector(v_name, v_x, v_y, y_z):
v_x_name = '%s_x' % v_name
v_y_name = '%s_y' % v_name
v_z_name = '%s_z' % v_name
v = v_x * e_x + v_y * e_y + v_z * e_z
return {v_name: v, v_x_name: v_x, v_y_name: v_y, v_z_name: v_z}
In [12]:
locals().update(point('a'))
A = pt(a)
locals().update(point('c'))
C = pt(c)
locals().update(point('s'))
S = pt(s)
locals().update(point('n', s_y, -s_x, 0))
I = e_x^e_y^e_z
II = e_x^e_y^e_z^e_0^e_oo
A = pt(a)
C = pt(c)
S = pt(a + s)
N = pt(a + n)
m = I*(s^n)
M = pt(a + m)
In [13]:
x = sym.Symbol('x')
In [14]:
plane_1 =((A^M^S^e_oo))
plane_2 =((A^C^S^e_oo))
In [15]:
EQ=(plane_1<plane_2)
E1=(plane_1<plane_1)
E2=(plane_2<plane_2)
In [16]:
from sympy.solvers import solve
import sympy as sym
from sympy import Symbol
In [17]:
EQ
Out[17]:
In [18]:
EQ.obj
Out[18]:
In [19]:
solve(EQ.obj, a_x)
Out[19]:
In [20]:
solve(sym.cos(x) - EQ.obj, x)
Out[20]:
In [21]:
solve(sym.cos(x) - a_x*s_x, x)
Out[21]:
In [22]:
from sympy.solvers import solve
import sympy as sym
from sympy import Symbol
In [23]:
EQQ=EQ.subs({a_x:10, a_y: 24, a_z: 20,c_x:10, c_y: 26, c_z: 20,s_x:10, s_y:11, s_z: 20})
E1Q=E1.subs({a_x:10, a_y: 24, a_z: 20,c_x:10, c_y: 26, c_z: 20,s_x:10, s_y:11, s_z: 20})
E2Q=E2.subs({a_x:10, a_y: 24, a_z: 20,c_x:10, c_y: 26, c_z: 20,s_x:10, s_y:11, s_z: 20})
In [24]:
EQQ/(E1Q*E2Q)
Out[24]:
In [25]:
sym.acos(float(11/6862050))
Out[25]:
In [ ]: