// 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 ; }