From: r90p@jupiter.sun.csd.unb.ca (Martin Schulz)
Subject: drawing conic sections using homogeneous (4d) coordinates?
Organization: University of New Brunswick
Date: Tue, 14 Apr 1992 05:55:33 GMT

I have to write a program which must be able to draw conic sections
i.e. circles, parabolas and hyperbolas in arbitrary places.

Since these are 'real' conic sections, starting with the equations
of a cone and a plane lets me easily compute the coefficients of
the general quadratic equation { E-1 }:

	A * x^2  +  B * x * y  +  C * y^2  +  D * x  + E * y  +  F = 0

I am looking for a really simple and elegant way to draw the underlying
curve -- if it exists.  In particular I was wondering if any circles
in 4d homogeneous coordinates might be helpful.  Below I will summarize
the traditional way of doing it (so that I won't get this explained
117 times...  :-)

The eq. above can also be put in matrix form:
		
		    ( A    B/2	D/2  )	   ( x )
		    (		     )     (   )
	(x,y,1)  X  ( B/2  C	E/2  )  X  ( y )  = 0		{ E-2 }
		    (		     )     (   )
		    ( D/2  E/2	F    )     ( 1 )

( If there is an error some place, forgive me )

Now let  d = B^2 - 4 A * C					{ E-3 }

					( A  B/2 )
which is  4 times the determinant of    (        )  from above,
					( B/2  C )

and D = determinant of the 3x3 matrix in E-2,
we can easily decide which shape E-1 will produce:

If D != 0:
	d == 0 	==> parabola
	d  < 0  ==> ellipse ( possibly imaginary, if (A+C)*D > 0 )
	d  > 0  ==> hyperbola
else ( D == 0 )
	different cases of lines, parallels and imaginary stuff.

All this is old stuff and can be found in any book on analytic geometry.
Then, traditionally, they explain how to rotate and translate these
conics to have them in normal positions.

Now the question is how to draw the original conic.

What I did so far was follow the route described above, compute all the
angles and translations, scale the whole thing, stuff all this into
a matrix and invert the whole thing.

Now I can compute the points of a

	the unit circle	x^2 + y^2 - 1 = 0
	the parabola	x^2 - y       = 0
	the hyperbola	x^2 - y^2 - 1 = 0

and use the found transformation to map this to the original conic.
(Of course the points of the circle, parabola and hyperbola
 can be computed in different ways efficiently)

Implementing all this correctly took me a while,  but now it works.
However the code is lengthy and looks clumsy.

BUT...

There is another way to draw a parabola:

Using homogeneous coordinates, which map (x,y,z) -> (x/z, y/z)
(for 2 dimensions), you can easily draw a hyperbola
using the parametric curve
	c = ( sin(phi)+0.5, cos(phi), sin(phi)+0.5 )	{ E-4 }
'c' in this case is an ellipse in 3D which will produce a hyperbola.

The same technique works for 3D too, but the 4-dimensional
homogeneous coordinate system is hard to imagine.

My question is:

Is there an easy and understandable algorithm to obtain from  E-1
some easy parametric curve (preferably just one similar to E-4)
and a handy 3x3 (or 4x4 in the 3d case) transformation matrix to
map that curve to the conic described by E-1 ?

Ideally, what I want to do (using something like the GL library)
is:

	t = compute_transform_matrix_from_coeffs

	...

	pushmatrix		// add the conic specific transform
	m = get4dmatrix		// to the graphics pipeline.
	m = mult4x4(m,t)
	loadmatrix(m)

	start_polyline		// now draw the thing
	loop
				// lookup the parametric curve
				// which is ideally independent of t !
		p = next_point_of_parametric_curve
		v4(p);		// enter this point and let the graphics
				// engine do all the hard work
	end
	end_polyline

	popmatrix


Of course an important condition would be that for 2 given points
on the conic their parameters for the parametric curve can be
easily obtained!

If this works independently of the shape (ellipse, parabola or hyperbola)
I would prefer this more elegant approach.

I guess I did not look hard enough, but in any case I have not found
anything usable in this direction -- and I would not like to figure it
out for myself.

Literature references or source code appreciated (_no_ FORTRAN please).
Many thanks in advance!

Email: martin@clement.info.umoncton.ca