Skip to content

Instantly share code, notes, and snippets.

@arokem
Created November 17, 2016 15:57
Show Gist options
  • Select an option

  • Save arokem/c4e912d191e30faea3ec2097e72ca7f4 to your computer and use it in GitHub Desktop.

Select an option

Save arokem/c4e912d191e30faea3ec2097e72ca7f4 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 45,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"from numpy import sin, cos\n",
"import dipy.core.geometry as gm"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def rotation_matrix(x, y, z):\n",
" Rx = np.array([[1, 0, 0], [0, cos(x), sin(x)], [0, -sin(x), cos(x)]])\n",
" Ry = np.array([[cos(y), 0, -sin(y)], [0, 1, 0], [sin(y), 0, cos(y)]])\n",
" Rz = np.array([[cos(z), sin(z), 0], [-sin(z), cos(z), 0], [0, 0, 1]])\n",
" return np.linalg.inv(Rx@Ry@Rz)"
]
},
{
"cell_type": "code",
"execution_count": 68,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"for x in [-np.pi, 0, 10e-30, 1, 2*np.pi]:\n",
" for y in [-np.pi, 0, 10e-30, 1, 2*np.pi]:\n",
" for z in [-np.pi, 0, 10e-30, 1, 2*np.pi]:\n",
" R1 = rotation_matrix(x, y, z)\n",
" R2 = gm.euler_matrix(x, y, z)[:3, :3]\n",
"\n",
" assert np.allclose(R1, R2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment