Skip to content

Instantly share code, notes, and snippets.

@arsenovic
Created June 23, 2018 13:52
Show Gist options
  • Save arsenovic/43346edc6d6dd3d018efa2687c51c880 to your computer and use it in GitHub Desktop.
Save arsenovic/43346edc6d6dd3d018efa2687c51c880 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Cartan's Rotation Algorithms"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from clifford import eps\n",
"from clifford.tools import orthoFrames2Verser\n",
"from clifford.tools.g3c import * \n",
"from scipy import e"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"works\n"
]
}
],
"source": [
"def generate_rotation_rotor():\n",
" B = e123.project(random_bivector())\n",
" return e**B\n",
"\n",
"def generate_translation_rotor():\n",
" a = e123.project(layout.randomV())\n",
" return (1 + ninf *a / 2)\n",
"\n",
"# generates random vectors in g3\n",
"euc_vector = lambda: e123.project(layout.randomV())\n",
"\n",
"# Create random euclidean transformation from translations and rotation\n",
"T = generate_translation_rotor()\n",
"R = generate_rotation_rotor()\n",
"V = T*R \n",
"\n",
"\n",
"a = [euc_vector() for k in range(4)] # create set of 4 vectors\n",
"A = list(map(up,a)) #\n",
"# homo() ==down/up roundtrip. observations are in g3, not g3c, so \n",
"# this is represented by doing a down/up round trip, which is just homo()\n",
"B = [homo(V*k*~V) for k in A] \n",
"\n",
"V_found,rs = orthoFrames2Verser(A=A,B=B, remove_scaling=1, det=1)\n",
"\n",
"if (min( abs(V_found+V),abs(V_found-V)) <eps() ):\n",
" print('works',)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(-0.59732 + (0.37407^e12) + (0.10978^e13) - (0.523^e14) - (0.523^e15) + (0.70088^e23) + (0.27335^e24) + (0.27335^e25) + (1.03019^e34) + (1.03019^e35) + (0.01875^e1234) + (0.01875^e1235),\n",
" -0.59732 + (0.37407^e12) + (0.10978^e13) - (0.523^e14) - (0.523^e15) + (0.70088^e23) + (0.27335^e24) + (0.27335^e25) + (1.03019^e34) + (1.03019^e35) + (0.01875^e1234) + (0.01875^e1235))"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"V_found,V"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The slowest run took 13.26 times longer than the fastest. This could mean that an intermediate result is being cached.\n",
"100 loops, best of 3: 3.56 ms per loop\n"
]
}
],
"source": [
"%%timeit\n",
"orthoFrames2Verser(A=A,B=B, remove_scaling=1, det=1)"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python [default]",
"language": "python",
"name": "python3"
},
"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