Created
August 19, 2018 22:29
-
-
Save hugohadfield/ad14fdf02bcf22e2e3eec897a405bb2e 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. | |
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) =>{ | |
y = -(x<<ninf); | |
adj = (y.Reverse); | |
madj = adj*y; | |
return x*(adj/madj); | |
}; | |
var down = (x)=>(homo(x)^E0)*E0; | |
// Define soem functions for manipulating objects | |
var plane2OriginDistance = (plane)=>((plane*I5)<<no)[0]; | |
var getPlaneNormal = (plane)=>(plane*I5 - plane2OriginDistance(plane)*ninf); | |
var circleNormal = (c)=>{ | |
Ic = (c^ninf).Normalized; | |
return getPlaneNormal(Ic); | |
}; | |
var circleToNormedInPlaneDual = (c)=>{ | |
Ic = (c^ninf).Normalized; | |
inPlaneDual = c*Ic; | |
mag = (inPlaneDual|ninf)[0]; | |
inPlaneDual = -inPlaneDual*(1/mag); | |
return inPlaneDual; | |
}; | |
var inPlaneDualCircleToRadius = (Ic)=>Math.sqrt((inPlaneDual*inPlaneDual)[0]); | |
var inPlaneDualCircleToCenter = (Ic)=>down(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; | |
return_data.normal = [myCircleNormal[0],myCircleNormal[1],myCircleNormal[2]]; | |
return_data.centre = [myCircleCenter[0],myCircleCenter[1],myCircleCenter[2]]; | |
return_data.radius = myCircleRadius; | |
return return_data; | |
}); | |
document.getElementById("demo").innerHTML = output | |
</SCRIPT> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Hugo,
Just wondering what your plan with this is ? You currently have a web CGA visualizer that relies on a python server backend ?
Do you have a specific application in mind ? Are you also handling visualizations for other dimensionalities, metrics and geometric interpretations ? What about non-euclidean geometries ?
Let me know if you're missing any crucial features in ganja.js or just need some help - happy to help out :)
Cheers,
Steven.