Last active
September 25, 2018 16:24
-
-
Save iamareebjamal/6f06c1afe797d3fac6bef3471eb69f3e to your computer and use it in GitHub Desktop.
Rotation Matrices
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 133, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "from sympy import *\n", | |
| "init_printing()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 134, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "x, y, z, t = symbols('x y z t')" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 135, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "theta1 = Function('f1')(t)\n", | |
| "theta2 = Function('f2')(t)\n", | |
| "theta3 = Function('f3')(t)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 136, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "S1, S2, S3 = sin(theta1), sin(theta2), sin(theta3)\n", | |
| "C1, C2, C3 = cos(theta1), cos(theta2), cos(theta3)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 137, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "M1 = Matrix([[C1, -S1, 0], [S1, C1, 0], [0, 0, 1]])\n", | |
| "M2 = Matrix([[1, 0, 0], [0, C2, -S2], [0, S2, C2]])\n", | |
| "M3 = Matrix([[C3, 0, S3], [0, 1, 0], [-S3, 0, C3]])" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 138, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/latex": [ | |
| "$$\\left ( \\left[\\begin{matrix}\\cos{\\left (\\operatorname{f_{1}}{\\left (t \\right )} \\right )} & - \\sin{\\left (\\operatorname{f_{1}}{\\left (t \\right )} \\right )} & 0\\\\\\sin{\\left (\\operatorname{f_{1}}{\\left (t \\right )} \\right )} & \\cos{\\left (\\operatorname{f_{1}}{\\left (t \\right )} \\right )} & 0\\\\0 & 0 & 1\\end{matrix}\\right], \\quad \\left[\\begin{matrix}1 & 0 & 0\\\\0 & \\cos{\\left (\\operatorname{f_{2}}{\\left (t \\right )} \\right )} & - \\sin{\\left (\\operatorname{f_{2}}{\\left (t \\right )} \\right )}\\\\0 & \\sin{\\left (\\operatorname{f_{2}}{\\left (t \\right )} \\right )} & \\cos{\\left (\\operatorname{f_{2}}{\\left (t \\right )} \\right )}\\end{matrix}\\right], \\quad \\left[\\begin{matrix}\\cos{\\left (\\operatorname{f_{3}}{\\left (t \\right )} \\right )} & 0 & \\sin{\\left (\\operatorname{f_{3}}{\\left (t \\right )} \\right )}\\\\0 & 1 & 0\\\\- \\sin{\\left (\\operatorname{f_{3}}{\\left (t \\right )} \\right )} & 0 & \\cos{\\left (\\operatorname{f_{3}}{\\left (t \\right )} \\right )}\\end{matrix}\\right]\\right )$$" | |
| ], | |
| "text/plain": [ | |
| "⎛⎡cos(f₁(t)) -sin(f₁(t)) 0⎤ ⎡1 0 0 ⎤ ⎡cos(f₃(t)) 0 \n", | |
| "⎜⎢ ⎥ ⎢ ⎥ ⎢ \n", | |
| "⎜⎢sin(f₁(t)) cos(f₁(t)) 0⎥, ⎢0 cos(f₂(t)) -sin(f₂(t))⎥, ⎢ 0 1 \n", | |
| "⎜⎢ ⎥ ⎢ ⎥ ⎢ \n", | |
| "⎝⎣ 0 0 1⎦ ⎣0 sin(f₂(t)) cos(f₂(t)) ⎦ ⎣-sin(f₃(t)) 0 \n", | |
| "\n", | |
| "sin(f₃(t))⎤⎞\n", | |
| " ⎥⎟\n", | |
| " 0 ⎥⎟\n", | |
| " ⎥⎟\n", | |
| "cos(f₃(t))⎦⎠" | |
| ] | |
| }, | |
| "execution_count": 138, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "M1, M2, M3" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 139, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "R = M1*M2*M3" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 140, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "Rdot = diff(R, t)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 141, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "result = Rdot*(R.T)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 142, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/latex": [ | |
| "$$\\left[\\begin{matrix}0 & - \\sin{\\left (\\operatorname{f_{2}}{\\left (t \\right )} \\right )} \\frac{d}{d t} \\operatorname{f_{3}}{\\left (t \\right )} - \\frac{d}{d t} \\operatorname{f_{1}}{\\left (t \\right )} & \\sin{\\left (\\operatorname{f_{1}}{\\left (t \\right )} \\right )} \\frac{d}{d t} \\operatorname{f_{2}}{\\left (t \\right )} + \\cos{\\left (\\operatorname{f_{1}}{\\left (t \\right )} \\right )} \\cos{\\left (\\operatorname{f_{2}}{\\left (t \\right )} \\right )} \\frac{d}{d t} \\operatorname{f_{3}}{\\left (t \\right )}\\\\\\sin{\\left (\\operatorname{f_{2}}{\\left (t \\right )} \\right )} \\frac{d}{d t} \\operatorname{f_{3}}{\\left (t \\right )} + \\frac{d}{d t} \\operatorname{f_{1}}{\\left (t \\right )} & 0 & \\sin{\\left (\\operatorname{f_{1}}{\\left (t \\right )} \\right )} \\cos{\\left (\\operatorname{f_{2}}{\\left (t \\right )} \\right )} \\frac{d}{d t} \\operatorname{f_{3}}{\\left (t \\right )} - \\cos{\\left (\\operatorname{f_{1}}{\\left (t \\right )} \\right )} \\frac{d}{d t} \\operatorname{f_{2}}{\\left (t \\right )}\\\\- \\sin{\\left (\\operatorname{f_{1}}{\\left (t \\right )} \\right )} \\frac{d}{d t} \\operatorname{f_{2}}{\\left (t \\right )} - \\cos{\\left (\\operatorname{f_{1}}{\\left (t \\right )} \\right )} \\cos{\\left (\\operatorname{f_{2}}{\\left (t \\right )} \\right )} \\frac{d}{d t} \\operatorname{f_{3}}{\\left (t \\right )} & - \\sin{\\left (\\operatorname{f_{1}}{\\left (t \\right )} \\right )} \\cos{\\left (\\operatorname{f_{2}}{\\left (t \\right )} \\right )} \\frac{d}{d t} \\operatorname{f_{3}}{\\left (t \\right )} + \\cos{\\left (\\operatorname{f_{1}}{\\left (t \\right )} \\right )} \\frac{d}{d t} \\operatorname{f_{2}}{\\left (t \\right )} & 0\\end{matrix}\\right]$$" | |
| ], | |
| "text/plain": [ | |
| "⎡ \n", | |
| "⎢ 0 - sin(f₂\n", | |
| "⎢ \n", | |
| "⎢ \n", | |
| "⎢ d d \n", | |
| "⎢ sin(f₂(t))⋅──(f₃(t)) + ──(f₁(t)) \n", | |
| "⎢ dt dt \n", | |
| "⎢ \n", | |
| "⎢ d d \n", | |
| "⎢- sin(f₁(t))⋅──(f₂(t)) - cos(f₁(t))⋅cos(f₂(t))⋅──(f₃(t)) - sin(f₁(t))⋅cos(f₂\n", | |
| "⎣ dt dt \n", | |
| "\n", | |
| " d d d \n", | |
| "(t))⋅──(f₃(t)) - ──(f₁(t)) sin(f₁(t))⋅──(f₂(t)) + cos(f₁(t))⋅cos(f\n", | |
| " dt dt dt \n", | |
| " \n", | |
| " d \n", | |
| " 0 sin(f₁(t))⋅cos(f₂(t))⋅──(f₃(t)) - cos(f\n", | |
| " dt \n", | |
| " \n", | |
| " d d \n", | |
| "(t))⋅──(f₃(t)) + cos(f₁(t))⋅──(f₂(t)) 0 \n", | |
| " dt dt \n", | |
| "\n", | |
| " d ⎤\n", | |
| "₂(t))⋅──(f₃(t))⎥\n", | |
| " dt ⎥\n", | |
| " ⎥\n", | |
| " d ⎥\n", | |
| "₁(t))⋅──(f₂(t))⎥\n", | |
| " dt ⎥\n", | |
| " ⎥\n", | |
| " ⎥\n", | |
| " ⎥\n", | |
| " ⎦" | |
| ] | |
| }, | |
| "execution_count": 142, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "simplify(result)" | |
| ] | |
| } | |
| ], | |
| "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.6.4" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 2 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment