Beispiel #1
0
void clSpline::SetControlPoints(const dMatrix &cPointsX, const dMatrix &cPointsY, const dMatrix &cPointsZ)
{
  // Check if dimensions are correct
  if((cPointsX.GetNumberColumns() != 1 || cPointsY.GetNumberColumns() != 1 || cPointsZ.GetNumberColumns() != 1) ||
     (cPointsX.GetNumberRows() != cPointsY.GetNumberRows()) ||
     (cPointsX.GetNumberRows() != cPointsZ.GetNumberRows()))
  {
    throw clException("clSpline", "SetControlPoints", "Dimensions of matrices do not match.");
  }
  else
  {
    X = cPointsX;
    Y = cPointsY;
    Z = cPointsZ;
  }
}
Beispiel #2
0
dMatrix clSpline::GetCoordinates(const dMatrix &uSpec)
{
  dMatrix coord;

  if(uSpec.GetNumberColumns() != 1 || uSpec.GetNumberRows() == 0)
  {
    throw clException("clSpline", "GetCoordinates", "Invalid dimensions of matrix uSpec.");
  }
  else
  {
    coord.SetNumberRows(uSpec.GetNumberRows());
    coord.SetNumberColumns(3);

    if(!initialised)
    {
      Initialise();
    }

    // Do for all specified u's
    for(int i=1; i<=uSpec.GetNumberRows(); i++)
    {
      if(uSpec(i, 1) < 0 || uSpec(i, 1) > 1)
      {
        throw clException("clSpline", "GetCoordinates", "Invalid value for uSpec.");
      }
      else
      {
        // Now find the position of uSpec
        double uu = uSpec(i, 1)*GetSplineLength();

        int j = 1;
        while((uu - u(j+1, 1) > 0) && (j<u.GetNumberRows()-1))
        {
          j++;
        }

        // Now calculate the coefficients
        double A = (u(j+1, 1)-uu)/(u(j+1, 1)-u(j,1));
        double B = 1-A;
        double C = (A*A*A-A)/6 * (u(j+1, 1)-u(j, 1))*(u(j+1, 1)-u(j, 1));
        double D = (B*B*B-B)/6 * (u(j+1, 1)-u(j, 1))*(u(j+1, 1)-u(j, 1));

        // Finally calculate the coordinates
        coord.SetElement(i, 1, A*X(j, 1) + B*X(j+1, 1) + C*X2(j, 1) + D*X2(j+1, 1));
        coord.SetElement(i, 2, A*Y(j, 1) + B*Y(j+1, 1) + C*Y2(j, 1) + D*Y2(j+1, 1));
        coord.SetElement(i, 3, A*Z(j, 1) + B*Z(j+1, 1) + C*Z2(j, 1) + D*Z2(j+1, 1));
      }
    }
  }

  return (coord);
}
Beispiel #3
0
void clSpline::SetControlPoints(const dMatrix &cPoints)
{
  // Check if matrix is in correct format.
  //   3 columns; 1 = x; 2 = y; 3 = z
  //   Number of rows is number of control points
  if(cPoints.GetNumberColumns() != 3)
  {
    throw clException("clSpline", "SetControlPoints", "Incorrect number of columns.");
  }
  else
  {
    int rmax = cPoints.GetNumberColumns();
    X.SetNumberRows(rmax); X.SetNumberColumns(1);
    Y.SetNumberRows(rmax); Y.SetNumberColumns(1);
    Z.SetNumberRows(rmax); Z.SetNumberColumns(1);

    for(int i=1; i<=rmax; i++)
    {
      X.SetElement(i, 1, cPoints(i, 1));
      Y.SetElement(i, 1, cPoints(i, 2));
      Z.SetElement(i, 1, cPoints(i, 3));
    }
  }
}