Published
Edited
Sep 24, 2020
Insert cell
md`# 2D CGA test with gangja.js`
Insert cell
Algebra = require('ganja.js')
Insert cell
// Create a Clifford Algebra with 3,1 metric for 2D CGA.
Algebra(3,1,()=>{

// The conformal model adds in more element types. (circles, point-pairs)
// We no longer work in a dual space. (so ^ = join and & = meet)
// Vectors are points, Bivectors are point pairs, Trivectors are lines/circles

// We don't work directly in the e3/e4 basis, but instead rotate it so we have
// two null vectors to work with (called origin and infinite)
var ni = 1e4+1e3, // n-infinite
no = .5e4-.5e3; // n-origin
// Define points, lines, circles using the null basis.
var point = (x,y)=>no + x*1e1 + y*1e2 + 0.5*(x*x+y*y)*ni,
line = (a,b,c)=>!(a*1e1 + b*1e2 + c*ni),
circle = (x,y,r)=>!(point(x,y) - r**2/2*ni);
var up = (x)=> no + x + .5*x*x*ni;
// Distances and Angles.
var dist=(x,y)=>(2*(x<<y).Length)**0.5,
angle=(x,y)=>Math.acos(!x.Normalized<<!y.Normalized);
// Define things
var B = line(1,0,0), // boundary
p1 = point(-1,0),
p2 = point(0,1),
ray1 = () => (p1^p2^ni); // incoming ray
// The constructions
var P = () => up((ni^no)<<(ray1&B^no));//, // intersection point of ray1 and B,
// Graph these items.
return (this.graph([
p1, p2,
ray1, "r1",
0x000000,
B, "B",
0xFF0000,
P, "P",
],{conformal:true,grid:true})); // conformal flag!

});
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more