Exemplo n.º 1
0
/*
 *  FindRoots :
 *	Given a 5th-degree equation in Bernstein-Bezier form, find
 *	all of the roots in the interval [0, 1].  Return the number
 *	of roots found.
 */
static int FindRoots(
    Geom::Point 	*w,			/* The control points		*/
    int 	degree,		/* The degree of the polynomial	*/
    double 	*t,			/* RETURN candidate t-values	*/
    int 	depth)		/* The depth of the recursion	*/
{  
    int 	i;
    Geom::Point 	Left[W_DEGREE+1],	/* New left and right 		*/
        Right[W_DEGREE+1];	/* control polygons		*/
    int 	left_count,		/* Solution count from		*/
        right_count;		/* children			*/
    double 	left_t[W_DEGREE+1],	/* Solutions from kids		*/
        right_t[W_DEGREE+1];

    switch (CrossingCount(w, degree)) {
    case 0 : {	/* No solutions here	*/
        return 0;	
        break;
    }
    case 1 : {	/* Unique solution	*/
        /* Stop recursion when the tree is deep enough	*/
        /* if deep enough, return 1 solution at midpoint 	*/
        if (depth >= MAXDEPTH) {
            t[0] = (w[0][Geom::X] + w[W_DEGREE][Geom::X]) / 2.0;
            return 1;
        }
        if (ControlPolygonFlatEnough(w, degree)) {
            t[0] = ComputeXIntercept(w, degree);
            return 1;
        }
        break;
    }
    }

    /* Otherwise, solve recursively after	*/
    /* subdividing control polygon		*/
    Bez(w, degree, 0.5, Left, Right);
    left_count  = FindRoots(Left,  degree, left_t, depth+1);
    right_count = FindRoots(Right, degree, right_t, depth+1);


    /* Gather solutions together	*/
    for (i = 0; i < left_count; i++) {
        t[i] = left_t[i];
    }
    for (i = 0; i < right_count; i++) {
        t[i+left_count] = right_t[i];
    }

    /* Send back total number of solutions	*/
    return (left_count+right_count);
}
Exemplo n.º 2
0
/*
 *  FindRoots :
 *	Given a 5th-degree equation in Bernstein-Bezier form, find
 *	all of the roots in the interval [0, 1].  Return the number
 *	of roots found.
 */
int Measurement::FindRoots(QPointF* w, int degree,double *t,int depth)
{
    int 	i;
    QPointF 	Left[W_DEGREE+1],	/* New left and right 		*/
            Right[W_DEGREE+1];	/* control polygons		*/
    int 	left_count,		/* Solution count from		*/
            right_count;		/* children			*/
    double 	left_t[W_DEGREE+1],	/* Solutions from kids		*/
            right_t[W_DEGREE+1];

    switch (CrossingCount(w, degree)) {
    case 0 : {	/* No solutions here	*/
        return 0;
    }
    case 1 : {	/* Unique solution	*/
        /* Stop recursion when the tree is deep enough	*/
        /* if deep enough, return 1 solution at midpoint 	*/
        if (depth >= MAXDEPTH) {
            t[0] = (w[0].rx() + w[W_DEGREE].rx()) / 2.0;
            return 1;
        }
        if (ControlPolygonFlatEnough(w, degree)) {
            t[0] = ComputeXIntercept(w, degree);
            return 1;
        }
        break;
    }
    }

    /* Otherwise, solve recursively after	*/
    /* subdividing control polygon		*/
    Bezier(w, degree, 0.5, Left, Right);
    left_count  = FindRoots(Left,  degree, left_t, depth+1);
    right_count = FindRoots(Right, degree, right_t, depth+1);


    /* Gather solutions together	*/
    for (i = 0; i < left_count; i++) {
        t[i] = left_t[i];
    }
    for (i = 0; i < right_count; i++) {
        t[i+left_count] = right_t[i];
    }

    /* Send back total number of solutions	*/
    return (left_count+right_count);
}
Exemplo n.º 3
0
// FindRoots :
//      Given a 5th-degree equation in Bernstein-Bezier form, find
//      all of the roots in the interval [0, 1].  Return the number
//      of roots found.
// Parameters :
//      w: The control points
//      degree: The degree of the polynomial
//      t: output candidate t-values
//      depth: The depth of the recursion
//
static int FindRoots(const Point2d* w, int degree, float* t, int depth)
{
    int i;
    Point2d Left[W_DEGREE+1];   // New left and right
    Point2d Right[W_DEGREE+1];  // control polygons
    int     left_count;         // Solution count from children
    int     right_count;
    float  left_t[W_DEGREE+1]; // Solutions from kids
    float  right_t[W_DEGREE+1];

    switch (CrossingCount(w, degree))
    {
    case 0 :    // No solutions here
        return 0;

    case 1 :    // Unique solution
        // Stop recursion when the tree is deep enough
        // if deep enough, return 1 solution at midpoint
        if (depth >= MAXDEPTH)
        {
            t[0] = (w[0].x + w[W_DEGREE].x) / 2;
            return 1;
        }
        if (ControlPolygonFlatEnough(w, degree)) {
            t[0] = ComputeXIntercept(w, degree);
            return 1;
        }
        break;
    }

    // Otherwise, solve recursively after subdividing control polygon
    BezierPoint(w, degree, 0.5f, Left, Right);
    left_count  = FindRoots(Left,  degree, left_t, depth+1);
    right_count = FindRoots(Right, degree, right_t, depth+1);

    // Gather solutions together
    for (i = 0; i < left_count; i++) {
        t[i] = left_t[i];
    }
    for (i = 0; i < right_count; i++) {
        t[i+left_count] = right_t[i];
    }

    // Send back total number of solutions
    return (left_count+right_count);
}