{{ message }}

Instantly share code, notes, and snippets.

# mirrornerror/quaternion_rotation.ipynb

Last active Mar 29, 2021
Quaternion rotation
 { "cells": [ { "metadata": {}, "cell_type": "markdown", "source": "# Quaternion Rotation" }, { "metadata": {}, "cell_type": "markdown", "source": "## quaternion rotation: \n#### given vectors and angle: \n
\nvector: P = [px, py, pz],  (P should be normalized: P / |P|)  \nunit vector (rotation axis): U = [ux, uy, uz],  (U should be normalized: U / |U|)  \nrotation angle: θ  \n
\n#### quaternion equations: \n
\nquaternion: P = [pw, px, py, pz]\nquaternion: Q = [cos(θ/2), ux * sin(θ/2), uy * sin(θ/2), uz * sin(θ/2)]\nquaternion: Q-1 = [cos(θ/2), ux * sin(θ/2), uy * sin(θ/2), uz * sin(θ/2)]\n\nquaternion multiplication: q1 * q2 = [q1w, q1x, q1y, q1z] * [q2w, q2x, q2y, q2z] \n                                   = [[q1w * q2w - q1x * q2x - q1y * q2y - q1z * q2z],\n                                      [q1w * q2x + q1x * q2w + q1y * q2z - q1z * q2y],\n                                      [q1w * q2y - q1x * q2z + q1y * q2w + q1z * q2x], \n                                      [q1w * q2z + q1x * q2y - q1y * q2x + q1z * q2w]]\n\nquaternion rotation: [w, x, y, z] = Q * P * Q-1,  (use quaternion multiplication: (Q * P) * Q-1)\n
\n#### new vector after quaternion rotation: \n
\nvector: [x, y, z]\n