toconic Previous  Next

int toconic(FLOAT p0, FLOAT p1, FLOAT p2, FLOAT p3, FLOAT p4,
FLOAT *a, FLOAT *b, FLOAT *c, FLOAT *d, FLOAT *e, FLOAT *f)

/* Code to find the equation of a conic */
/*               Tom Davis              */
/*             April 12, 1996           */

/* toconic takes five points in homogeneous coordinates, and returns the
* coefficients of a general conic equation in a, b, c, ..., f:
*
* a*x*x + b*x*y + c*y*y + d*x + e*y + f = 0.
*
* The routine returns 1 on success; 0 otherwise.  (It can fail, for
* example, if there are duplicate points.
*
* Typically, the points will be finite, in which case the third (w)
* coordinate for all the input vectors will be 1, although the code
* deals cleanly with points at infinity.
*
* For example, to find the equation of the conic passing through (5, 0),
* (-5, 0), (3, 2), (3, -2), and (-3, 2), set:
*
* p0 =  5, p0 =  0, p0 = 1,
* p1 = -5, p1 =  0, p1 = 1,
* p2 =  3, p2 =  2, p2 = 1,
* p3 =  3, p3 = -2, p3 = 1,
* p4 = -3, p4 =  2, p4 = 1.
*
* But if you want the equation of the hyperbola that is tangent to the
* line 2x=y at infinity,  simply make one of the points be the point at
* infinity along that line, for example:
*
* p0 = 1, p0 = 2, p0 = 0.
*/