Ejemplo n.º 1
0
void writeBezier(ofstream &out, unsigned step, double px[], double py[]) {
  out << "%%%%%%%%%%%%%%%%%%" << endl;
  out << "%% Bezier-Kurve %%" << endl;
  out << "%%%%%%%%%%%%%%%%%%" << endl;
  out << "\\drawline";
  for (unsigned i= 0; i <= step; ++i) {
    double x;
    double y;
    curvePoint(double(i)/double(step), px, x);
    curvePoint(double(i)/double(step), py, y);
    out << "(" << OFS+(int)x << "," << OFS+(int)y << ")";
    if ((i % 5) == 4) {
      out << endl << "\t";
    }
  }
  out << endl;
}
Ejemplo n.º 2
0
Coord computeOpenUniformBsplinePoint(const vector<Coord> &controlPoints, const float t, const unsigned int curveDegree) {
  assert(controlPoints.size() > 3);
  unsigned int nbKnots = controlPoints.size() + curveDegree + 1;
  float stepKnots = 1.0f / ((static_cast<float>(nbKnots) - 2.0f * (static_cast<float>(curveDegree) + 1.0f)) + 2.0f - 1.0f);

  if (t == 0.0) {
    return controlPoints[0];
  }
  else if (t >= 1.0) {
    return controlPoints[controlPoints.size() - 1];
  }
  else {
    float* coeffs = new float[curveDegree + 1];
    memset(coeffs, 0, (curveDegree + 1) * sizeof(float));
    int k = curveDegree;
    int cpt = 0;

    while (t > (cpt*stepKnots) && t >= ((cpt+1)*stepKnots)) {
      ++k;
      ++cpt;
    }

    float knotVal = (cpt * stepKnots);
    coeffs[curveDegree] = 1.0;

    for (int i = 1 ; i <= static_cast<int>(curveDegree) ; ++i) {
      coeffs[curveDegree-i] = (clamp(knotVal + stepKnots, 0.0, 1.0) - t) / (clamp(knotVal + stepKnots, 0.0, 1.0) - clamp(knotVal + (-i+1) * stepKnots, 0.0, 1.0)) * coeffs[curveDegree-i+1];
      int tabIdx = curveDegree-i+1;

      for (int j = -i+1 ; j <= -1 ; ++j) {
        coeffs[tabIdx] = ((t - clamp(knotVal + j * stepKnots, 0.0, 1.0)) / (clamp(knotVal + (j+i) * stepKnots, 0.0, 1.0) - clamp(knotVal + j * stepKnots, 0.0, 1.0))) * coeffs[tabIdx] + ((clamp(knotVal + (j+i+1) * stepKnots, 0.0, 1.0) - t) / (clamp(knotVal + (j+i+1) * stepKnots, 0.0, 1.0) - clamp(knotVal + (j+1) * stepKnots, 0.0, 1.0))) * coeffs[tabIdx+1];
        ++tabIdx;
      }

      coeffs[curveDegree] = ((t - knotVal) / (clamp(knotVal + i * stepKnots, 0.0, 1.0) - knotVal)) * coeffs[curveDegree];
    }

    Coord curvePoint(0.0f, 0.0f, 0.0f);
    int startIdx = k - curveDegree;

    for (unsigned int i = 0 ; i <= curveDegree ; ++i) {
      curvePoint += coeffs[i] * controlPoints[startIdx + i];
    }

    delete [] coeffs;
    return curvePoint;
  }
}
Ejemplo n.º 3
0
void curvePoints(S_Curve *pCurve, int n, S_CoordVec *pPoints)
{
    double  step, t = 0.0;
    int     i, size;

    IZG_ASSERT(pCurve && pPoints);

    /* uprava velikosti vysledneho seznamu bodu */
    size = curveSize(pCurve);
    cvecResize(pPoints, size);

    /* pocet ridicich bodu */
    if( size < 2 || n < 2 ) return;

    /* vypocet velikosti kroku */
    step = 1.0 / (n - 1);

    /* generovani bodu */
    for( i = 0; i < n; ++i, t += step )
    {
        /* vypocet bodu krivky */
        cvecGet(pPoints, i) = curvePoint(pCurve, t);
    }
}