mathr / blog / #

ray42: nD raytracing

compound of five cubes

I've been rewriting ray4 from scratch in C++, extending it to arbitrary dimensions, providing various Constructive Solid Geometry operations, trying out procedural textures, playing around in general. It's way too slow though, the ray tracing algorithm is completely naive and tests every object against every ray, no oct-tree optimisations here. But it seems to generate some pretty pictures, or even animations, if you're prepared to wait a while.

So far I've tested with 3D and 4D, and it seems to work to some extent.

Meanwhile, way back in 2006 I was trying to make a compound of five cubes, well it turned out my maths was wrong - instead of (Scheme):

(define A (* 90 (atan (* 2 (- 0.5 (/ (- (sqrt 5) 2) (- 3 (sqrt 5))))))))

I should have been using (C++):

double a(std::atan(2.0l / (1.0l + std::sqrt(5.0l))));

Now the corners line up perfectly, hooray!