Intersection of ray with quadric surface for hobby ray tracer

Practical and theoretical implementation discussion.
asyrov
Posts: 9
Joined: Mon Oct 12, 2015 9:38 pm

Intersection of ray with quadric surface for hobby ray tracer

I'm looking into ways to add more shapes to my hobby path tracer, such as cylinder, cone, ellipse. So, I'm at this reference:
http://www.bmsc.washington.edu/people/m ... drics.html which is taken from Lindley book on ray tracing (which I also have, but without CD). It briefly explains generalized quadratic formula with A...J parameters and how to calculate normals.

While this could be what I need, there is no much detail on meaning of AJ parameters. For instance If I take ellipse, then ideally I would want to specify it in terms of 'a' and 'b' radius on the x and y exes respectively, origin and orientation (3x3 matrix).

Thank you very much in advance.

szellmann
Posts: 51
Joined: Fri Oct 10, 2014 9:15 am
Contact:

Re: Intersection of ray with quadric surface for hobby ray tracer

Here's an explanation of how to build up the 4x4 matrix for several quadric types: https://www.siggraph.org/education/mate ... inter4.htm

I believe that Glassner's 1980's book "Introduction to Ray Tracing" also has a paragraph on this.

There's a ray/quadric implementation in the ray tracing skeleton program of the programming course that I teach at University: https://vis.uni-koeln.de/raytracer0.html (the program itself won't compile out the box, making it compile is part of the students' task, anyhow, the "geoquadric" class should work right away).

Cheers, Stefan

szellmann
Posts: 51
Joined: Fri Oct 10, 2014 9:15 am
Contact:

Re: Intersection of ray with quadric surface for hobby ray tracer

This here paper btw. uses quadrics to project 3-D ellipsoids to 2-D: https://pdfs.semanticscholar.org/df2e/0 ... b231e6.pdf

hobold
Posts: 56
Joined: Wed Dec 21, 2011 6:08 pm

Re: Intersection of ray with quadric surface for hobby ray tracer

The explanation behind general quadrics is not so simple and obvious. It does get quite tedious doing the math with 10 quadric coefficients and 12 more coefficients of a general affine transform.

If you feel like digging through the source code of another toy raytracer, I can offer an older experiment of mine:

http://www.vectorizer.org/boar/boarCore1.tar.bz2

http://www.vectorizer.org/boar/boarCore ... nt.tar.bz2

The first tarball is just the source. In transform.c++ is code for the usual rotations and translations, as well as concatenating such transforms. In quadric.c++ there are initialization routines for common shapes (sphere, cylinder, cone) and less common shapes (slab, lathe, product of planes). The quadric class also knows how to transform a quadric given an affine transform.

The second tarball contains an explanation of the scene description language (heavily inspired by PoV-Ray, http://www.povray.org), and an example scene file. I think the three syntaxes (in the doc, in the actual parser, and in the example scene) do slightly differ from each other - this is not a proper release, sorry.

The source code is moderately commented. I have since abandoned this particular approach, but will gladly answer any questions you might have.

asyrov
Posts: 9
Joined: Mon Oct 12, 2015 9:38 pm

Re: Intersection of ray with quadric surface for hobby ray tracer

Thanks a lot! I'm still testing, but it started to work now.
Also found relatively simple and compact ref here: https://people.cs.clemson.edu/~dhouse/c ... adrics.pdf
My next challenge is solid constructions.

hobold
Posts: 56
Joined: Wed Dec 21, 2011 6:08 pm

Re: Intersection of ray with quadric surface for hobby ray tracer

asyrov wrote:My next challenge is solid constructions.
My code above is not a good reference for constructive solid geometry. It does have a rather inefficient implementation; but that would only make sense in conjunction with spatial subdivision (where the voxels contained only pruned CSG subtrees).

ziu
Posts: 29
Joined: Sat Aug 17, 2013 8:46 pm

Re: Intersection of ray with quadric surface for hobby ray tracer

BRL-CAD has OpenCL code for quite a lot of primitives: