Public
Edited
Apr 30, 2024
Insert cell
Insert cell
Algebra = require('ganja.js')
Insert cell
res = Algebra(3,0,1,()=>{
let point = (x,y,z) => !(x*1e1 + y*1e2 + z*1e3 + 1e0);
let vec = (x, y, z) => !(x*1e1 + y*1e2 + z*1e3 + 0e0);

let A = point(-1, -1, 0), B = point(-1, 1, 1), C = point(1, 1, -1);

let AB = () => A & B, BC = () => B & C, CA = () => C & A;

let O = point(0, -1, 0);
let Ray = () => O & vec(-.1, 1, 0);

let i = () => Ray ^ (A & B & C);

let s = () => (Ray & AB), t = () => (Ray & BC), r = () => (Ray & CA);

let hit = () => {
let sign = s().s >=0;
return sign === t().s >=0 && sign == r().s >= 0;
};

let j = () => Ray & (A & B & C);

return {
s: s(),
graph: this.graph([
() => `s:${s()}, t:${t()}, r:${r()}, ${hit()}`,
() => `j:${j()}`,
0x008844,
A, "A",
B, "B",
C, "C",
() => hit() ? 0xA0FFE1 : 0xFFA0E1,
[A, B, C],
0x00AA88,
AB, BC, CA,
O, "O",
Ray, "Ray",
i, "i",
], {
grid: true,
labels: true,
lineWidth: 3,
pointRadius: 1,
fontSize: 1,
scale: 1
})};
});
Insert cell
res.graph
Insert cell
res.s.s
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