Last active
June 11, 2020 04:30
-
-
Save d3x0r/e23fc4509070a96fe4e08e23601f2695 to your computer and use it in GitHub Desktop.
Revisions
-
d3x0r revised this gist
Jun 11, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ // 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 -
d3x0r revised this gist
Jun 11, 2020 . 1 changed file with 13 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,15 +4,22 @@ function lnQuat( theta, d ){ const dl = 1/Math.sqrt( d.x*d.x + d.y*d.y + d.z*d.z ); 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 ) -
d3x0r revised this gist
Jun 11, 2020 . 1 changed file with 12 additions and 9 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,5 @@ // 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 ); @@ -17,10 +10,20 @@ function lnQuat( theta, d, a, b ){ const x = dl * d.x * st2; // sqrt( 1/2(1 - cos theta)) const y = dl * d.y * st2; // const z = dl * d.z * st2; // 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 ; } -
d3x0r created this gist
Jun 11, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ function lnQuat( theta, d, a, b ){ if( "undefined" !== typeof theta ) { if( "undefined" !== typeof a ) { // create with 4 raw coordinates this.w = theta; this.x = d; this.y = a; this.z = b; }else { // if no rotation, then nothing. const dl = 1/Math.sqrt( d.x*d.x + d.y*d.y + d.z*d.z ); const t = theta/2; const ct2 = Math.cos( t ); // sqrt( 1/2(1 + cos theta)) const st2 = Math.sin( t ); // sqrt( 1/2(1 - cos theta)) const w = ct2; // sqrt( 1/2(1 + cos theta)) const x = dl * d.x * st2; // sqrt( 1/2(1 - cos theta)) 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+y*y+z*z ) // 1/2(1 + cos theta) + 1/2(1 - cos theta) * ( x*x+y*y+z*z ) // 1/2(1 + cos theta) + 1/2(1 - cos theta) * (1) // 1/2 ( 1 + cos theta + 1 - cos theta) // 1 const r = w*w + x*x+y*y+z*z ;