Select Git revision
raytracing1.ts 983 B
import Playground from "./playground";
const pg = new Playground();
const sphere = {
position: [0, .5, -3],
radius: 1.23
}
pg.visCamera(-1);
pg.gridXZ()
const o = [0, 0, 0]
const co = ... // O - C
const step = 1 / 8
for (let yCoord = -1; yCoord <= 1; yCoord += step) {
for (let xCoord = -1; xCoord <= 1; xCoord += step) {
const v = [xCoord, yCoord, -1]
const ov = ... // V - O
pg.visVector(ov)
const a = ... // <---- see equations above
const b = ... // <---- see equations above
const c = ... // <---- see equations above
const discriminant = ... // <---- see equations above
const t1 = (-b + Math.sqrt(discriminant)) / (2 * a)
const t2 = (-b - Math.sqrt(discriminant)) / (2 * a)
if (t1) {
pg.visPoint(vecMultiplyScalar(t1, v),{color:"red"});
}
if (t2) {
pg.visPoint(vecMultiplyScalar(t2, v),{color:"blue"});
}
}
}