Guest User

Untitled

a guest
Jul 18th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.67 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "markdown",
  5. "metadata": {},
  6. "source": [
  7. "# Object Oriented CGA "
  8. ]
  9. },
  10. {
  11. "cell_type": "markdown",
  12. "metadata": {},
  13. "source": [
  14. " 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. "
  15. ]
  16. },
  17. {
  18. "cell_type": "markdown",
  19. "metadata": {},
  20. "source": [
  21. "## Quick Use Demo"
  22. ]
  23. },
  24. {
  25. "cell_type": "code",
  26. "execution_count": 26,
  27. "metadata": {},
  28. "outputs": [
  29. {
  30. "data": {
  31. "text/plain": [
  32. "(1.0^e1235)"
  33. ]
  34. },
  35. "execution_count": 26,
  36. "metadata": {},
  37. "output_type": "execute_result"
  38. }
  39. ],
  40. "source": [
  41. "from clifford.cga import CGA, Sphere, Translation\n",
  42. "from clifford import Cl\n",
  43. "\n",
  44. "ga,blades = Cl(3) # you can change dimensions\n",
  45. "cga = CGA(ga)\n",
  46. "\n",
  47. "locals().update(ga.blades) # put ga's blades in local namespace\n",
  48. "\n",
  49. "C = cga.sphere(e1,e2,e3,-e2) # generate unit sphere from points \n",
  50. "C.mv # any CGA object/operator has a multivector repr"
  51. ]
  52. },
  53. {
  54. "cell_type": "code",
  55. "execution_count": 27,
  56. "metadata": {},
  57. "outputs": [
  58. {
  59. "data": {
  60. "text/plain": [
  61. "(0, 1.0)"
  62. ]
  63. },
  64. "execution_count": 27,
  65. "metadata": {},
  66. "output_type": "execute_result"
  67. }
  68. ],
  69. "source": [
  70. "cga.down(C.center),C.radius # some properties of spheres"
  71. ]
  72. },
  73. {
  74. "cell_type": "code",
  75. "execution_count": 13,
  76. "metadata": {},
  77. "outputs": [
  78. {
  79. "data": {
  80. "text/plain": [
  81. "(1.0^e1) + (1.0^e2)"
  82. ]
  83. },
  84. "execution_count": 13,
  85. "metadata": {},
  86. "output_type": "execute_result"
  87. }
  88. ],
  89. "source": [
  90. "T = cga.translation(e1+e2) # make a translation \n",
  91. "C_ = T(C) # translate the sphere \n",
  92. "cga.down(C_.center) # compute center again"
  93. ]
  94. },
  95. {
  96. "cell_type": "code",
  97. "execution_count": 14,
  98. "metadata": {},
  99. "outputs": [
  100. {
  101. "data": {
  102. "text/plain": [
  103. "<clifford.cga.Translation at 0x7f55e0eea358>"
  104. ]
  105. },
  106. "execution_count": 14,
  107. "metadata": {},
  108. "output_type": "execute_result"
  109. }
  110. ],
  111. "source": [
  112. "cga.sphere() # no args == random sphere \n",
  113. "cga.translation() # random translation "
  114. ]
  115. },
  116. {
  117. "cell_type": "markdown",
  118. "metadata": {},
  119. "source": [
  120. "# more details "
  121. ]
  122. },
  123. {
  124. "cell_type": "markdown",
  125. "metadata": {},
  126. "source": [
  127. "## Objects "
  128. ]
  129. },
  130. {
  131. "cell_type": "markdown",
  132. "metadata": {},
  133. "source": [
  134. "### Vectors "
  135. ]
  136. },
  137. {
  138. "cell_type": "code",
  139. "execution_count": 5,
  140. "metadata": {
  141. "code_folding": []
  142. },
  143. "outputs": [
  144. {
  145. "data": {
  146. "text/plain": [
  147. "(1.11758^e1) - (1.49541^e2) - (0.77589^e3)"
  148. ]
  149. },
  150. "execution_count": 5,
  151. "metadata": {},
  152. "output_type": "execute_result"
  153. }
  154. ],
  155. "source": [
  156. "a = cga.lower_vector() # exists in ga, not cga \n",
  157. "a"
  158. ]
  159. },
  160. {
  161. "cell_type": "code",
  162. "execution_count": 6,
  163. "metadata": {},
  164. "outputs": [
  165. {
  166. "data": {
  167. "text/plain": [
  168. "(1.11758^e1) - (1.49541^e2) - (0.77589^e3) + (1.54362^e4) + (2.54362^e5)"
  169. ]
  170. },
  171. "execution_count": 6,
  172. "metadata": {},
  173. "output_type": "execute_result"
  174. }
  175. ],
  176. "source": [
  177. "A = cga.up(a) # exists in cga, not ga \n",
  178. "A"
  179. ]
  180. },
  181. {
  182. "cell_type": "code",
  183. "execution_count": 7,
  184. "metadata": {},
  185. "outputs": [],
  186. "source": [
  187. "a_ = cga.down(A) # back in ga\n",
  188. "assert(a_.layout ==a.layout)"
  189. ]
  190. },
  191. {
  192. "cell_type": "code",
  193. "execution_count": 8,
  194. "metadata": {},
  195. "outputs": [
  196. {
  197. "data": {
  198. "text/plain": [
  199. "-(0.66034^e1) - (1.36113^e2) - (1.71379^e3) + (2.1129^e4) + (3.1129^e5)"
  200. ]
  201. },
  202. "execution_count": 8,
  203. "metadata": {},
  204. "output_type": "execute_result"
  205. }
  206. ],
  207. "source": [
  208. "cga.null_vector() # create null vector directly"
  209. ]
  210. },
  211. {
  212. "cell_type": "markdown",
  213. "metadata": {},
  214. "source": [
  215. "### Sphere (point pair, circles)"
  216. ]
  217. },
  218. {
  219. "cell_type": "code",
  220. "execution_count": 29,
  221. "metadata": {},
  222. "outputs": [
  223. {
  224. "data": {
  225. "text/plain": [
  226. "(1.0^e125)"
  227. ]
  228. },
  229. "execution_count": 29,
  230. "metadata": {},
  231. "output_type": "execute_result"
  232. }
  233. ],
  234. "source": [
  235. "C = cga.sphere(e1, e2,-e1,e3) # generates sphere from points\n",
  236. "C = cga.sphere(e1, e2,-e1) # generates circle from points\n",
  237. "C2 = cga.sphere(2) # random 2-sphere (sphere)\n",
  238. "C1 = cga.sphere(1) # random 1-sphere, (circle)\n",
  239. "C0 = cga.sphere(0) # random 0-sphere, (point pair)\n",
  240. "\n",
  241. "cga.down(C1.center)\n",
  242. "C.mv # access the multivector"
  243. ]
  244. },
  245. {
  246. "cell_type": "code",
  247. "execution_count": 30,
  248. "metadata": {},
  249. "outputs": [
  250. {
  251. "data": {
  252. "text/plain": [
  253. "-(1.0^e4) + (1.0^e5)"
  254. ]
  255. },
  256. "execution_count": 30,
  257. "metadata": {},
  258. "output_type": "execute_result"
  259. }
  260. ],
  261. "source": [
  262. "C.center # spheres have properties"
  263. ]
  264. },
  265. {
  266. "cell_type": "code",
  267. "execution_count": 31,
  268. "metadata": {},
  269. "outputs": [
  270. {
  271. "data": {
  272. "text/plain": [
  273. "True"
  274. ]
  275. },
  276. "execution_count": 31,
  277. "metadata": {},
  278. "output_type": "execute_result"
  279. }
  280. ],
  281. "source": [
  282. "cga.down(C.center) == C.center_down #down projected center"
  283. ]
  284. },
  285. {
  286. "cell_type": "markdown",
  287. "metadata": {},
  288. "source": [
  289. "### Operators"
  290. ]
  291. },
  292. {
  293. "cell_type": "code",
  294. "execution_count": 19,
  295. "metadata": {},
  296. "outputs": [
  297. {
  298. "data": {
  299. "text/plain": [
  300. "1.0 - (0.5^e14) - (0.5^e15)"
  301. ]
  302. },
  303. "execution_count": 19,
  304. "metadata": {},
  305. "output_type": "execute_result"
  306. }
  307. ],
  308. "source": [
  309. "T = cga.translation(e1) # generate translation \n",
  310. "T.mv "
  311. ]
  312. },
  313. {
  314. "cell_type": "code",
  315. "execution_count": 21,
  316. "metadata": {},
  317. "outputs": [
  318. {
  319. "data": {
  320. "text/plain": [
  321. "-(0.5^e1234) + (0.5^e1235) + (1.0^e2345)"
  322. ]
  323. },
  324. "execution_count": 21,
  325. "metadata": {},
  326. "output_type": "execute_result"
  327. }
  328. ],
  329. "source": [
  330. "T.mv*C.mv*~T.mv # translate a sphere "
  331. ]
  332. },
  333. {
  334. "cell_type": "code",
  335. "execution_count": 24,
  336. "metadata": {},
  337. "outputs": [
  338. {
  339. "data": {
  340. "text/plain": [
  341. "-(0.5^e1234) + (0.5^e1235) + (1.0^e2345)"
  342. ]
  343. },
  344. "execution_count": 24,
  345. "metadata": {},
  346. "output_type": "execute_result"
  347. }
  348. ],
  349. "source": [
  350. "T(C).mv # shorthand call, same as above"
  351. ]
  352. },
  353. {
  354. "cell_type": "code",
  355. "execution_count": null,
  356. "metadata": {},
  357. "outputs": [],
  358. "source": []
  359. }
  360. ],
  361. "metadata": {
  362. "kernelspec": {
  363. "display_name": "Python [conda root]",
  364. "language": "python",
  365. "name": "conda-root-py"
  366. },
  367. "language_info": {
  368. "codemirror_mode": {
  369. "name": "ipython",
  370. "version": 3
  371. },
  372. "file_extension": ".py",
  373. "mimetype": "text/x-python",
  374. "name": "python",
  375. "nbconvert_exporter": "python",
  376. "pygments_lexer": "ipython3",
  377. "version": "3.5.2"
  378. },
  379. "toc": {
  380. "nav_menu": {},
  381. "number_sections": true,
  382. "sideBar": true,
  383. "skip_h1_title": false,
  384. "toc_cell": false,
  385. "toc_position": {},
  386. "toc_section_display": "block",
  387. "toc_window_display": false
  388. }
  389. },
  390. "nbformat": 4,
  391. "nbformat_minor": 2
  392. }
Add Comment
Please, Sign In to add comment