-
-
Save enkimute/c462fc7e33e70869f5262cbd6a153958 to your computer and use it in GitHub Desktop.
This file contains 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>title</title> | |
<link rel="stylesheet" href="style.css"> | |
<SCRIPT SRC="../ganja.js"></SCRIPT> | |
</head> | |
<body> | |
<p id="demo"></p> | |
<SCRIPT> | |
// Create a Clifford Algebra with 4,1 metric for 3D CGA. | |
/// my comments have three bars. | |
/// In general, you had some parse errors - because ganja.js has to translate your code that's not always clear (most of the time it | |
/// is fine tho) in that case I just comment out blocks to find out where. | |
/// next, for debugging, I recommend adding a 'debugger' statement anywhere in the code, this will stop the execution | |
/// and show you the translated code where you can easily stop over, inspect, change values etc .. | |
/// Lastly, don't get stuck on things - I'm more than happy to help and would love to see how your 4,1 visualizer works | |
/// with ganja.js :) | |
var output = Algebra(4,1,()=>{ | |
// Define some useful things | |
var ninf = 1e4+1e5; | |
var nbar = 1e4-1e5; | |
var no = 0.5*nbar; | |
var I5 = 1e12345; | |
var E0 = ninf^(-no); | |
// We need up and down mapping as well | |
var up = (x)=>0.5*(x*x*ninf + 2*x - nbar); | |
var homo = (x) =>{ | |
var y = 0e1-1*(x<<ninf), /// two gotcha's here .. the dot could produce a pure scalar, after which reverse wont work. | |
adj = (y.Reverse), /// so I forced it to a multivector with the 0e1+ | |
madj = adj*y; | |
return x*(adj/madj); | |
}; | |
var down = (x)=>(0e1+homo(0e1+x)^E0)*E0; | |
// Define some functions for manipulating objects | |
var plane2OriginDistance = (plane)=>((plane*I5)<<no)[0]; | |
var getPlaneNormal = (plane)=>(plane*I5 - plane2OriginDistance(plane)*ninf); | |
var circleNormal = (c)=>{ | |
var Ic = (c^ninf).Normalized; /// had no 'var' - js strict mode needs it (and you want strict mode) | |
return getPlaneNormal(Ic); | |
}; | |
var circleToNormedInPlaneDual = (c)=>{ | |
var Ic = (c^ninf).Normalized, /// same .. had no 'var' | |
inPlaneDual = c*Ic, | |
mag = (inPlaneDual<<ninf)[0]; | |
inPlaneDual = inPlaneDual*(-1/mag); | |
return inPlaneDual; | |
}; | |
var inPlaneDualCircleToRadius = (inPlaneDual)=>Math.sqrt((inPlaneDual*inPlaneDual)[0]); | |
var inPlaneDualCircleToCenter = (inPlaneDual)=>down(0e1+inPlaneDual*(1+0.5*inPlaneDual*ninf)); | |
// Define geometric primitive creation routines | |
var euc_point = (x,y,z)=>x*1e1 + y*1e2 + z*1e3; | |
var circle = (p1,p2,p3)=>(p1^p2^p3).Normalized; | |
// Now lets actually attempt to do something | |
var p_a = up(1e3 + 1e1); | |
var p_b = up(1e3 - 1e1); | |
var p_c = up(1e3 + 1e2); | |
var myCircle = circle(p_a,p_b,p_c); | |
var myCircleNormal = circleNormal(myCircle); | |
var myCircleDual = circleToNormedInPlaneDual(myCircle); | |
var myCircleRadius = inPlaneDualCircleToRadius(myCircleDual); | |
var myCircleCenter = inPlaneDualCircleToCenter(myCircleDual); | |
var return_data={ | |
normal : myCircleNormal.slice(1,4), // you had [0] [1] [2] .. but you wanted [1][2][3] .. slice just is faster here. | |
centre : myCircleCenter.slice(1,4), | |
radius : myCircleRadius | |
} | |
console.log(return_data); /// press shift+ctrl+i or shift+command+i for the developper console where this outputs. | |
return return_data; | |
}); | |
document.getElementById("demo").innerHTML = '<PRE>'+JSON.stringify(output)+'</PRE>' | |
</SCRIPT> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment