Calculating number of bezier curve graph points

74 Views Asked by At

I want to paint a smooth bezier curve in a 2D pane. The number of control points is probably irrelevant to my question.

The question is, in the loop of $B(t)$ calculation, https://en.wikipedia.org/wiki/B%C3%A9zier_curve#Explicit_definition, how can I efficiently calculate the $t$ variable step?

Currently I do the following:

int manhattan_x = BiggestXAxisDifferenceOfControlPoints();
int manhattan_y = BiggestYAxisDifferenceOfControlPoints();
int min_points = sqrt(pow(manhattan_x, 2) + pow(manhattan_y, 2));
double step = 1.0 / double(min_points);

for (int np = 0; np <= min_points; np++) {
        double x = 0;
        double y = 0;
        double t = np*step;
        for (int i = 0; i <= n; i++) {
            int coeff = binomialCoeff(n, i);
            x += coeff * pow((1 - t), n - i) * pow(t, i) * ctrl_points_->at(i).x();
            y += coeff * pow((1 - t), n - i) * pow(t, i) * ctrl_points_->at(i).y();
        }
        bzr_points[np].x = x;
        bzr_points[np].y = y;
    }