Skip to content

Instantly share code, notes, and snippets.

@arsenovic
Created July 18, 2018 18:41
Show Gist options
  • Save arsenovic/f23c696c17f3ee7de529028d0cfcc085 to your computer and use it in GitHub Desktop.
Save arsenovic/f23c696c17f3ee7de529028d0cfcc085 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Object Oriented CGA "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" 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. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Quick Use Demo"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(1.0^e1235)"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from clifford.cga import CGA, Sphere, Translation\n",
"from clifford import Cl\n",
"\n",
"ga,blades = Cl(3) # you can change dimensions\n",
"cga = CGA(ga)\n",
"\n",
"locals().update(ga.blades) # put ga's blades in local namespace\n",
"\n",
"C = cga.sphere(e1,e2,e3,-e2) # generate unit sphere from points \n",
"C.mv # any CGA object/operator has a multivector repr"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(0, 1.0)"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cga.down(C.center),C.radius # some properties of spheres"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(1.0^e1) + (1.0^e2)"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"T = cga.translation(e1+e2) # make a translation \n",
"C_ = T(C) # translate the sphere \n",
"cga.down(C_.center) # compute center again"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<clifford.cga.Translation at 0x7f55e0eea358>"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cga.sphere() # no args == random sphere \n",
"cga.translation() # random translation "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# more details "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Objects "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Vectors "
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"code_folding": []
},
"outputs": [
{
"data": {
"text/plain": [
"(1.11758^e1) - (1.49541^e2) - (0.77589^e3)"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a = cga.lower_vector() # exists in ga, not cga \n",
"a"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(1.11758^e1) - (1.49541^e2) - (0.77589^e3) + (1.54362^e4) + (2.54362^e5)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"A = cga.up(a) # exists in cga, not ga \n",
"A"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"a_ = cga.down(A) # back in ga\n",
"assert(a_.layout ==a.layout)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-(0.66034^e1) - (1.36113^e2) - (1.71379^e3) + (2.1129^e4) + (3.1129^e5)"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cga.null_vector() # create null vector directly"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Sphere (point pair, circles)"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(1.0^e125)"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"C = cga.sphere(e1, e2,-e1,e3) # generates sphere from points\n",
"C = cga.sphere(e1, e2,-e1) # generates circle from points\n",
"C2 = cga.sphere(2) # random 2-sphere (sphere)\n",
"C1 = cga.sphere(1) # random 1-sphere, (circle)\n",
"C0 = cga.sphere(0) # random 0-sphere, (point pair)\n",
"\n",
"cga.down(C1.center)\n",
"C.mv # access the multivector"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-(1.0^e4) + (1.0^e5)"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"C.center # spheres have properties"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cga.down(C.center) == C.center_down #down projected center"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Operators"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1.0 - (0.5^e14) - (0.5^e15)"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"T = cga.translation(e1) # generate translation \n",
"T.mv "
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-(0.5^e1234) + (0.5^e1235) + (1.0^e2345)"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"T.mv*C.mv*~T.mv # translate a sphere "
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-(0.5^e1234) + (0.5^e1235) + (1.0^e2345)"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"T(C).mv # shorthand call, same as above"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda root]",
"language": "python",
"name": "conda-root-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
},
"toc": {
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"toc_cell": false,
"toc_position": {},
"toc_section_display": "block",
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment