Published
Edited
Apr 9, 2018
Fork of ganja.js
5 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
intersection = CGA3D.inline((extract_detailed) => {
const ei = 1e5 + 1e4; // e_infty
const eo = .5 * (1e5 - 1e4); // e_0
// (and apparently, swapping the +/- in both e0 and ei is OK)
const E = ei^eo;
const eq = (a,b) => a-b == 0; // can't use == for array equality
const pt = (x,y,z) => x*1e1 + y*1e2 + z*1e3 + .5*(x*x+y*y+z*z)*ei + eo;
// var a = pt(4,5,6);
// var b = pt(7,8,9);
// var d = Math.hypot(7-4, 8-5, 9-6);
// return eq(a<<b, -.5*d*d); // true
const extract = pp => {
const r = Math.sqrt(Math.abs((pp << pp)[0]));
const le = pp << (ei^pp) - (pp << pp)*ei;
const ri = r*(ei << pp);
const denom = (ei << pp)**2;
return [
-(le - ri) / denom,
-(le + ri) / denom,
];
};
var sphere1 = pt(3,0,-.5)^pt(-1,0,-.5)^pt(1,2,-.5)^pt(1,0,1.5);
var sphere2 = pt(3,0,1)^pt(-1,0,1)^pt(1,2,1)^pt(1,0,3);
var line = pt(0,0,0)^pt(1,0,0)^ei;
var intersection1 = (sphere1&line);
// return [extract(intersection1), extract_detailed(intersection1)];
return extract(intersection1); // <-- WORKS
var sphere3 = pt(4,1,0)^pt(0,1,0)^pt(2,3,0)^pt(2,1,2);
var intersection2 = (sphere3&sphere2&sphere1);
return extract(intersection2); // <!-- does not work, but in particular, /denom = /bignumber => 0
return [intersection1, intersection2, (sphere1&sphere2)];
})(extract_detailed)
Insert cell
Insert cell
Insert cell
CGA3D.inline((extract_detailed) => {
const ei = 1e5 + 1e4; const _ei = x => .5*(x/1e5 + x/1e4);
const eo = .5 * (1e5 - 1e4); const _eo = x => (x/1e5 - x/1e4);
// (and apparently, swapping the +/- in both e0 and ei is OK)
const E = ei^eo;
const eq = (a,b) => a-b == 0; // can't use == for array equality
const pt = (x,y,z) => x*1e1 + y*1e2 + z*1e3 + .5*(x*x+y*y+z*z)*ei + eo;
const extract = pp => {
const r = Math.sqrt(Math.abs((pp << pp)[0]));
const le = pp << (ei^pp) - (pp << pp)*ei;
const ri = r*(ei << pp);
const denom = (ei << pp)**2;
return [
-(le - ri) / denom,
-(le + ri) / denom,
];
};
const pa = 3e1 + 4e2 + 5e3;
const pb = 7e1 + 8e2 + 9e3;
const a = pt(3,4,5);
const b = pt(7,8,9);
const V = a^b;
/*
const extract_detailed = pp => {
const _b = ((V / 1e12)[0])*1e12 + ((V / 1e13)[0])*1e13 + ((V / 1e23)[0])*1e23; // Euclidean bivector
const _gamma = 2 * (V / 1e45)[0];
var _v = 2*_ei(V); _v = _v[1]*1e1 + _v[2]*1e2 + _v[3]*1e3;
var _u = -_eo(V); _u = _u[1]*1e1 + _u[2]*1e2 + _u[3]*1e3;
// V = _b + .5*_v*ei - _u*eo + .5*_gamma*E

const _sigma = .5*_gamma**2 - (_u << _v)[0];
const _rho = Math.sqrt(_sigma**2 - _u**2 * _v**2);
const _pa_len = Math.sqrt(_sigma + _rho) / _u.Length;
const _pb_len = Math.sqrt(_sigma - _rho) / _u.Length;
const _pa = _pa_len*(_pa_len**2*_u + _v).Normalized;
const _pb = _pb_len*(_pb_len**2*_u + _v).Normalized;
return [_pa,_pb];
}
*/
const myV = pa^pb + .5*(pa**2*pb - pb**2*pa)*ei - (pb-pa)*eo + .5*(pa**2 - pb**2)*E;
// https://arxiv.org/pdf/1306.1007.pdf
return [extract_detailed(V), extract(V)];
})(extract_detailed)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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