Professional Documents
Culture Documents
The following code is the complete algorithm for the general conic
drawer as mentioned in Foley/VanDam. It is included here with the
permission of Andrew W. Fitzgibbon, who derived the remaining code
sections not included in the book.
//
// CONIC 2D Bresenham-like conic drawer.
// CONIC(Sx,Sy, Ex,Ey, A,B,C,D,E,F) draws the conic specified
// by A x^2 + B x y + C y^2 + D x + E y + F = 0, between the
// start point (Sx, Sy) and endpoint (Ex,Ey).
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int debugging = 1;
struct ConicPlotter {
virtual void plot(int x, int y);
};
int octant;
int d;
if (debugging) {
// Translate start point to origin...
float tF = A*xs*xs + B*xs*ys + C*ys*ys + D*xs + E*ys + F;
float tD = D + 2 * A * xs + B * ys;
float tE = E + B * xs + 2 * C * ys;
int x = xs;
int y = ys;
if (odd(octant)) {
while (2*v <= k2) {
// Plot this point
((DebugPlotter*)plotterdata)->octant = octant;
((DebugPlotter*)plotterdata)->d = d;
plotterdata->plot(x,y);
octant = (octant&7)+1;
octantcount--;
}
if (odd(octant)) {
while (2*v <= k2 && x != xe && y != ye) {
// Plot this point
((DebugPlotter*)plotterdata)->octant = octant;
((DebugPlotter*)plotterdata)->d = d;
plotterdata->plot(x,y);
return 1;
}