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]:
$$\left[\begin{matrix}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\end{matrix}\right]$$

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]:
\begin{equation*} - a_{x} {\left ( s_{x} \right )}^{3} s_{z} - a_{x} s_{x} {\left ( s_{y} \right )}^{2} s_{z} - a_{x} s_{x} {\left ( s_{z} \right )}^{3} - a_{y} {\left ( s_{x} \right )}^{2} s_{y} s_{z} - a_{y} {\left ( s_{y} \right )}^{3} s_{z} - a_{y} s_{y} {\left ( s_{z} \right )}^{3} + a_{z} {\left ( s_{x} \right )}^{4} + 2 a_{z} {\left ( s_{x} \right )}^{2} {\left ( s_{y} \right )}^{2} + a_{z} {\left ( s_{x} \right )}^{2} {\left ( s_{z} \right )}^{2} + a_{z} {\left ( s_{y} \right )}^{4} + a_{z} {\left ( s_{y} \right )}^{2} {\left ( s_{z} \right )}^{2} + c_{x} {\left ( s_{x} \right )}^{3} s_{z} + c_{x} s_{x} {\left ( s_{y} \right )}^{2} s_{z} + c_{x} s_{x} {\left ( s_{z} \right )}^{3} + c_{y} {\left ( s_{x} \right )}^{2} s_{y} s_{z} + c_{y} {\left ( s_{y} \right )}^{3} s_{z} + c_{y} s_{y} {\left ( s_{z} \right )}^{3} - c_{z} {\left ( s_{x} \right )}^{4} - 2 c_{z} {\left ( s_{x} \right )}^{2} {\left ( s_{y} \right )}^{2} - c_{z} {\left ( s_{x} \right )}^{2} {\left ( s_{z} \right )}^{2} - c_{z} {\left ( s_{y} \right )}^{4} - c_{z} {\left ( s_{y} \right )}^{2} {\left ( s_{z} \right )}^{2} \end{equation*}

In [11]:
EQ.obj


Out[11]:
$$- a_{x} s_{x}^{3} s_{z} - a_{x} s_{x} s_{y}^{2} s_{z} - a_{x} s_{x} s_{z}^{3} - a_{y} s_{x}^{2} s_{y} s_{z} - a_{y} s_{y}^{3} s_{z} - a_{y} s_{y} s_{z}^{3} + a_{z} s_{x}^{4} + 2 a_{z} s_{x}^{2} s_{y}^{2} + a_{z} s_{x}^{2} s_{z}^{2} + a_{z} s_{y}^{4} + a_{z} s_{y}^{2} s_{z}^{2} + c_{x} s_{x}^{3} s_{z} + c_{x} s_{x} s_{y}^{2} s_{z} + c_{x} s_{x} s_{z}^{3} + c_{y} s_{x}^{2} s_{y} s_{z} + c_{y} s_{y}^{3} s_{z} + c_{y} s_{y} s_{z}^{3} - c_{z} s_{x}^{4} - 2 c_{z} s_{x}^{2} s_{y}^{2} - c_{z} s_{x}^{2} s_{z}^{2} - c_{z} s_{y}^{4} - c_{z} s_{y}^{2} s_{z}^{2}$$

In [12]:
solve(EQ.obj, ax)


Out[12]:
$$\left [ \frac{- a_{y} s_{y} s_{z} + a_{z} s_{x}^{2} + a_{z} s_{y}^{2} + c_{x} s_{x} s_{z} + c_{y} s_{y} s_{z} - c_{z} s_{x}^{2} - c_{z} s_{y}^{2}}{s_{x} s_{z}}\right ]$$

In [13]:
solve(sym.cos(x) - EQ.obj, x)


Out[13]:
$$\left [ - \operatorname{acos}{\left (- \left(s_{x}^{2} + s_{y}^{2} + s_{z}^{2}\right) \left(a_{x} s_{x} s_{z} + a_{y} s_{y} s_{z} - a_{z} s_{x}^{2} - a_{z} s_{y}^{2} - c_{x} s_{x} s_{z} - c_{y} s_{y} s_{z} + c_{z} s_{x}^{2} + c_{z} s_{y}^{2}\right) \right )} + 2 \pi, \quad \operatorname{acos}{\left (- \left(s_{x}^{2} + s_{y}^{2} + s_{z}^{2}\right) \left(a_{x} s_{x} s_{z} + a_{y} s_{y} s_{z} - a_{z} s_{x}^{2} - a_{z} s_{y}^{2} - c_{x} s_{x} s_{z} - c_{y} s_{y} s_{z} + c_{z} s_{x}^{2} + c_{z} s_{y}^{2}\right) \right )}\right ]$$

In [14]:
solve(sym.cos(x) - ax*sx, x)


Out[14]:
$$\left [ - \operatorname{acos}{\left (a_{x} s_{x} \right )} + 2 \pi, \quad \operatorname{acos}{\left (a_{x} s_{x} \right )}\right ]$$

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]:
\begin{equation*} \frac{11}{6862050} \end{equation*}

In [18]:
sym.acos(float(11/6862050))


Out[18]:
$$1.57079472377539$$

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]:
\begin{equation*} \boldsymbol{e}_{x} \end{equation*}

In [5]:
e_y


Out[5]:
\begin{equation*} \boldsymbol{e}_{y} \end{equation*}

In [6]:
e_z


Out[6]:
\begin{equation*} \boldsymbol{e}_{z} \end{equation*}

In [7]:
e_0


Out[7]:
\begin{equation*} \boldsymbol{e}_{{0}} \end{equation*}

In [8]:
e_oo


Out[8]:
\begin{equation*} \boldsymbol{e}_{{\infty}} \end{equation*}

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]:
\begin{equation*} - a_{x} {\left ( s_{x} \right )}^{3} s_{z} - a_{x} s_{x} {\left ( s_{y} \right )}^{2} s_{z} - a_{x} s_{x} {\left ( s_{z} \right )}^{3} - a_{y} {\left ( s_{x} \right )}^{2} s_{y} s_{z} - a_{y} {\left ( s_{y} \right )}^{3} s_{z} - a_{y} s_{y} {\left ( s_{z} \right )}^{3} + a_{z} {\left ( s_{x} \right )}^{4} + 2 a_{z} {\left ( s_{x} \right )}^{2} {\left ( s_{y} \right )}^{2} + a_{z} {\left ( s_{x} \right )}^{2} {\left ( s_{z} \right )}^{2} + a_{z} {\left ( s_{y} \right )}^{4} + a_{z} {\left ( s_{y} \right )}^{2} {\left ( s_{z} \right )}^{2} + c_{x} {\left ( s_{x} \right )}^{3} s_{z} + c_{x} s_{x} {\left ( s_{y} \right )}^{2} s_{z} + c_{x} s_{x} {\left ( s_{z} \right )}^{3} + c_{y} {\left ( s_{x} \right )}^{2} s_{y} s_{z} + c_{y} {\left ( s_{y} \right )}^{3} s_{z} + c_{y} s_{y} {\left ( s_{z} \right )}^{3} - c_{z} {\left ( s_{x} \right )}^{4} - 2 c_{z} {\left ( s_{x} \right )}^{2} {\left ( s_{y} \right )}^{2} - c_{z} {\left ( s_{x} \right )}^{2} {\left ( s_{z} \right )}^{2} - c_{z} {\left ( s_{y} \right )}^{4} - c_{z} {\left ( s_{y} \right )}^{2} {\left ( s_{z} \right )}^{2} \end{equation*}

In [18]:
EQ.obj


Out[18]:
$$- a_{x} s_{x}^{3} s_{z} - a_{x} s_{x} s_{y}^{2} s_{z} - a_{x} s_{x} s_{z}^{3} - a_{y} s_{x}^{2} s_{y} s_{z} - a_{y} s_{y}^{3} s_{z} - a_{y} s_{y} s_{z}^{3} + a_{z} s_{x}^{4} + 2 a_{z} s_{x}^{2} s_{y}^{2} + a_{z} s_{x}^{2} s_{z}^{2} + a_{z} s_{y}^{4} + a_{z} s_{y}^{2} s_{z}^{2} + c_{x} s_{x}^{3} s_{z} + c_{x} s_{x} s_{y}^{2} s_{z} + c_{x} s_{x} s_{z}^{3} + c_{y} s_{x}^{2} s_{y} s_{z} + c_{y} s_{y}^{3} s_{z} + c_{y} s_{y} s_{z}^{3} - c_{z} s_{x}^{4} - 2 c_{z} s_{x}^{2} s_{y}^{2} - c_{z} s_{x}^{2} s_{z}^{2} - c_{z} s_{y}^{4} - c_{z} s_{y}^{2} s_{z}^{2}$$

In [19]:
solve(EQ.obj, a_x)


Out[19]:
$$\left [ \frac{- a_{y} s_{y} s_{z} + a_{z} s_{x}^{2} + a_{z} s_{y}^{2} + c_{x} s_{x} s_{z} + c_{y} s_{y} s_{z} - c_{z} s_{x}^{2} - c_{z} s_{y}^{2}}{s_{x} s_{z}}\right ]$$

In [20]:
solve(sym.cos(x) - EQ.obj, x)


Out[20]:
$$\left [ - \operatorname{acos}{\left (- \left(s_{x}^{2} + s_{y}^{2} + s_{z}^{2}\right) \left(a_{x} s_{x} s_{z} + a_{y} s_{y} s_{z} - a_{z} s_{x}^{2} - a_{z} s_{y}^{2} - c_{x} s_{x} s_{z} - c_{y} s_{y} s_{z} + c_{z} s_{x}^{2} + c_{z} s_{y}^{2}\right) \right )} + 2 \pi, \quad \operatorname{acos}{\left (- \left(s_{x}^{2} + s_{y}^{2} + s_{z}^{2}\right) \left(a_{x} s_{x} s_{z} + a_{y} s_{y} s_{z} - a_{z} s_{x}^{2} - a_{z} s_{y}^{2} - c_{x} s_{x} s_{z} - c_{y} s_{y} s_{z} + c_{z} s_{x}^{2} + c_{z} s_{y}^{2}\right) \right )}\right ]$$

In [21]:
solve(sym.cos(x) - a_x*s_x, x)


Out[21]:
$$\left [ - \operatorname{acos}{\left (a_{x} s_{x} \right )} + 2 \pi, \quad \operatorname{acos}{\left (a_{x} s_{x} \right )}\right ]$$

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]:
\begin{equation*} \frac{11}{6862050} \end{equation*}

In [25]:
sym.acos(float(11/6862050))


Out[25]:
$$1.57079472377539$$

In [ ]: