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

Postby asyrov » Fri Jan 20, 2017 7:48 pm

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).

Can anyone please point me to where to learn more about these AJs parameters or alternative (simple) approaches.

Thank you very much in advance.

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

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

Postby szellmann » Fri Jan 20, 2017 9:10 pm

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: 44
Joined: Fri Oct 10, 2014 9:15 am
Contact:

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

Postby szellmann » Fri Jan 20, 2017 9:44 pm

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

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

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

Postby hobold » Sun Jan 29, 2017 4:20 pm

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

Postby asyrov » Thu Feb 02, 2017 8:49 pm

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.
Attachments
path_trace-1.jpeg
path_trace-1.jpeg (45.77 KiB) Viewed 1847 times

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

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

Postby hobold » Fri Feb 03, 2017 5:02 am

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: 28
Joined: Sat Aug 17, 2013 8:46 pm

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

Postby ziu » Thu Apr 06, 2017 9:39 am

BRL-CAD has OpenCL code for quite a lot of primitives:
https://svn.code.sf.net/p/brlcad/code/b ... rimitives/

We are still working on porting primitives over but this is what we have already:
  • an equation solver (solves quartic, cubic, and quadric equations).
  • ray-primitive and surface normal code for: Bag o' Triangles (trimeshes), Arbitrary Polyhedrons, Elliptical Hyperboloids, Generalized Ellipsoids, Elliptical Paraboloids, Elliptical Torus, Right Elliptical Cylinders, Right Hyperbolic Cylinders, Right Parabolic Cylinders, Spheres, Truncated General Cones, Torus, and more...


Return to “General Development”

Who is online

Users browsing this forum: No registered users and 2 guests