Object Oriented CGA

This is a shelled out demo for a object-oriented approach to CGA with clifford. The CGA object holds the original layout for an arbitrary geometric algebra , and the conformalized version. It provides up/down projections, as well as easy ways to generate objects and operators.

Quick Use Demo

[1]:
from clifford.cga import CGA, Round, Translation
from clifford import Cl

g3,blades = Cl(3)

cga = CGA(g3)  # make cga from existing ga
# or
cga = CGA(3)   # generate cga from dimension of 'base space'

locals().update(cga.blades)        # put ga's blades in local namespace

C = cga.round(e1,e2,e3,-e2)      # generate unit sphere from points
C
[1]:
Sphere
[2]:
## Objects
cga.round()              # from None
cga.round(3)             # from dim of space
cga.round(e1,e2,e3,-e2)  # from points
cga.round(e1,e2,e3)      # from points
cga.round(e1,e2)         # from points
cga.round((e1,3))        # from center, radius
cga.round(cga.round().mv)# from existing multivector

cga.flat()               # from None
cga.flat(2)              # from dim of space
cga.flat(e1,e2)          # from points
cga.flat(cga.flat().mv)  # from existing multivector


## Operations
cga.dilation()          # from from None
cga.dilation(.4)        # from int

cga.translation()       # from None
cga.translation(e1+e2)  # from vector
cga.translation(cga.down(cga.null_vector()))

cga.rotation()          # from None
cga.rotation(e12+e23)   # from bivector

cga.transversion(e1+e2).mv
/home/docs/checkouts/readthedocs.org/user_builds/clifford/conda/latest/lib/python3.7/site-packages/clifford-1.0.5-py3.7.egg/clifford/__init__.py:1271: RuntimeWarning: divide by zero encountered in true_divide
/home/docs/checkouts/readthedocs.org/user_builds/clifford/conda/latest/lib/python3.7/site-packages/clifford-1.0.5-py3.7.egg/clifford/__init__.py:1271: RuntimeWarning: invalid value encountered in true_divide
[2]:
1.0 + (0.5^e14) - (0.5^e15) + (0.5^e24) - (0.5^e25)
[3]:
cga.round().inverted()
[3]:
-(0.32867^e1234) + (0.91151^e1235) + (0.15912^e1245) + (0.11761^e1345) + (0.48788^e2345)
[4]:
D = cga.dilation(5)
cga.down(D(e1))
[4]:
(5.0^e1)
[5]:
C.mv # any CGA object/operator has a multivector
[5]:
(1.0^e1235)
[6]:
C.center_down,C.radius # some properties of spheres
[6]:
(0, 1.0)
[7]:
T = cga.translation(e1+e2) # make a translation
C_ = T(C)                  # translate the sphere
cga.down(C_.center)        # compute center again
[7]:
(1.0^e1) + (1.0^e2)
[8]:
cga.round()       #  no args == random sphere
cga.translation() #             random translation
[8]:
Translation
[9]:
if 1 in map(int, [1,2]):
    print(3)
3

Objects

Vectors

[10]:
a = cga.base_vector()  # random vector with components in base space only
a
[10]:
-(0.83951^e1) + (1.18439^e2) - (0.70481^e3)
[11]:
cga.up(a)
[11]:
-(0.83951^e1) + (1.18439^e2) - (0.70481^e3) + (0.80216^e4) + (1.80216^e5)
[12]:
cga.null_vector()  # create null vector directly
[12]:
-(0.25688^e1) - (1.91649^e2) + (0.65049^e3) + (1.58103^e4) + (2.58103^e5)

Sphere (point pair, circles)

[13]:
C = cga.round(e1, e2, -e1, e3) # generates sphere from points
C = cga.round(e1, e2, -e1)     # generates circle from points
C = cga.round(e1, e2)          # generates point-pair from points
#or
C2 = cga.round(2)            # random 2-sphere  (sphere)
C1 = cga.round(1)            # random 1-sphere, (circle)
C0 = cga.round(0)            # random 0-sphere, (point pair)


C1.mv                        # access the multivector
[13]:
-(0.48248^e123) - (0.3629^e124) - (0.47048^e125) + (0.6181^e134) + (1.1211^e135) + (0.24052^e145) + (0.03023^e234) + (0.29057^e235) + (0.18908^e245) - (0.302^e345)
[14]:
C = cga.round(e1, e2, -e1, e3)
C.center,C.radius        # spheres have properties
[14]:
(-(1.0^e4) + (1.0^e5), 1.0)
[15]:
cga.down(C.center) == C.center_down
[15]:
True
[16]:
C_ = cga.round().from_center_radius(C.center,C.radius)
C_.center,C_.radius
[16]:
(-(2.0^e4) + (2.0^e5), 0.9999999999999999)

Operators

[17]:
T = cga.translation(e1) # generate translation
T.mv
[17]:
1.0 - (0.5^e14) - (0.5^e15)
[18]:
C = cga.round(e1, e2, -e1)
T.mv*C.mv*~T.mv         # translate a sphere
[18]:
-(0.5^e124) + (0.5^e125) - (1.0^e245)
[19]:
T(C)                # shorthand call, same as above. returns type of arg
[19]:
Circle
[20]:
T(C).center
[20]:
(2.0^e1) + (2.0^e5)
[ ]:

[ ]: