Skip to content

Instantly share code, notes, and snippets.

@d3x0r
Last active June 11, 2020 04:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d3x0r/e23fc4509070a96fe4e08e23601f2695 to your computer and use it in GitHub Desktop.
Save d3x0r/e23fc4509070a96fe4e08e23601f2695 to your computer and use it in GitHub Desktop.
compute initial log quaternion
// theta - angle in radians, d = {x, y, z } direction/unnormalized
function lnQuat( theta, d ){
// if no rotation, then nothing.
const dl = 1/Math.sqrt( d.x*d.x + d.y*d.y + d.z*d.z ); // 1/ d length = normalize d
const t = theta/2;
const ct2 = Math.cos( t ); // sqrt( 1/2(1 + cos theta)) - half angle subst
const st2 = Math.sin( t ); // sqrt( 1/2(1 - cos theta)) - half angle subst
const w = ct2;
const x = dl * d.x * st2;
const y = dl * d.y * st2;
const z = dl * d.z * st2;
// sqrt( 1/2(1 + cos theta)) * sqrt( 1/2(1 + cos theta))
// + sqrt( 1/2(1 - cos theta) )*sqrt( 1/2(1 - cos theta)) * x*x
// + sqrt( 1/2(1 - cos theta) )*sqrt( 1/2(1 - cos theta)) * y*y
// + sqrt( 1/2(1 - cos theta) )*sqrt( 1/2(1 - cos theta)) * z*z )
// for R below, substitute terms... (also factor x,y,z from sin value)
// sqrt( 1/2(1 + cos theta)) * sqrt( 1/2(1 + cos theta))
// + sqrt( 1/2(1 - cos theta))*sqrt( 1/2(1 - cos theta))
// * ( x*x+y*y+z*z )
// collapse sqrt(n)*sqrt(n) to n
// 1/2(1 + cos theta) + 1/2(1 - cos theta) * ( x*x+y*y+z*z )
// the length of the direction part is normalized and is always 1
// 1/2(1 + cos theta) + 1/2(1 - cos theta) * (1)
// 1/2 ( 1 + cos theta + 1 - cos theta)
// so this should always be 1??
// 1
const r = w*w + x*x+y*y+z*z ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment