This page was generated from docs/tutorials/cga/object-oriented.ipynb. Interactive online version: .

# 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¶

:

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

/home/docs/checkouts/readthedocs.org/user_builds/clifford/envs/latest/lib/python3.8/site-packages/pyganja/__init__.py:2: UserWarning: Failed to import cef_gui, cef functions will be unavailable
from .script_api import *

:

Sphere

:

## 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/envs/latest/lib/python3.8/site-packages/clifford/_multivector.py:281: RuntimeWarning: divide by zero encountered in true_divide
newValue = self.value / other
/home/docs/checkouts/readthedocs.org/user_builds/clifford/envs/latest/lib/python3.8/site-packages/clifford/_multivector.py:281: RuntimeWarning: invalid value encountered in true_divide
newValue = self.value / other

:

1.0 + (0.5^e14) - (0.5^e15) + (0.5^e24) - (0.5^e25)

:

cga.round().inverted()

:

(1.13371^e1234) - (1.42696^e1235) + (0.42033^e1245) + (0.02278^e1345) - (0.26808^e2345)

:

D = cga.dilation(5)
cga.down(D(e1))

:

(5.0^e1)

:

C.mv # any CGA object/operator has a multivector

:

(1.0^e1235)

:

C.center_down,C.radius # some properties of spheres

:

(0, 1.0)

:

T = cga.translation(e1+e2) # make a translation
C_ = T(C)                  # translate the sphere
cga.down(C_.center)        # compute center again

:

(1.0^e1) + (1.0^e2)

:

cga.round()       #  no args == random sphere
cga.translation() #             random translation

:

Translation

:

if 1 in map(int, [1,2]):
print(3)

3


## Objects¶

### Vectors¶

:

a = cga.base_vector()  # random vector with components in base space only
a

:

(1.48158^e1) + (0.18042^e2) + (1.61649^e3)

:

cga.up(a)

:

(1.48158^e1) + (0.18042^e2) + (1.61649^e3) + (1.92034^e4) + (2.92034^e5)

:

cga.null_vector()  # create null vector directly

:

(0.85176^e1) + (0.43193^e2) + (0.96957^e3) + (0.42607^e4) + (1.42607^e5)


### Sphere (point pair, circles)¶

:

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

:

(0.69416^e123) + (1.39543^e124) + (1.83274^e125) - (0.06353^e134) - (0.08008^e135) + (0.00675^e145) - (0.20587^e234) - (0.31779^e235) - (0.0953^e245) + (0.00533^e345)

:

C = cga.round(e1, e2, -e1, e3)
C.center,C.radius        # spheres have properties

:

(-(1.0^e4) + (1.0^e5), 1.0)

:

cga.down(C.center) == C.center_down

:

True

:

C_ = cga.round().from_center_radius(C.center,C.radius)
C_.center,C_.radius

:

(-(2.0^e4) + (2.0^e5), 0.7071067811865476)


### Operators¶

:

T = cga.translation(e1) # generate translation
T.mv

:

1.0 - (0.5^e14) - (0.5^e15)

:

C = cga.round(e1, e2, -e1)
T.mv*C.mv*~T.mv         # translate a sphere

:

-(0.5^e124) + (0.5^e125) - (1.0^e245)

:

T(C)                # shorthand call, same as above. returns type of arg

:

Circle

:

T(C).center

:

(2.0^e1) + (2.0^e5)

[ ]:



[ ]: