Example #1
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);
}
Example #2
0
void clSpline::FirstDerivatives(void)
{
  double deltaU;
  double deltaX;
  double deltaY;
  double deltaZ;

  // Get maximum number of rows
  int rmax = u.GetNumberRows();

  X1.SetNumberRows(rmax); X1.SetNumberColumns(1);
  Y1.SetNumberRows(rmax); Y1.SetNumberColumns(1);
  Z1.SetNumberRows(rmax); Z1.SetNumberColumns(1);

  for(int r=1; r<rmax; r++)
  {
    deltaU = u.GetElement(r+1, 1) - u.GetElement(r, 1);
    if(fabs(deltaU)<PRECISION)
    {
      deltaU = PRECISION;
      //throw clException("clSpline", "FirstDerivatives", "Division by zero.");
    }

    deltaX = X.GetElement(r+1, 1) - X.GetElement(r, 1);
    deltaY = Y.GetElement(r+1, 1) - Y.GetElement(r, 1);
    deltaZ = Z.GetElement(r+1, 1) - Z.GetElement(r, 1);

    X1.SetElement(r, 1, fabs(deltaX)*(deltaX/deltaU - deltaU*X2(r, 1)/3.0 - deltaU*X2(r+1, 1)/6.0));
    Y1.SetElement(r, 1, fabs(deltaY)*(deltaY/deltaU - deltaU*Y2(r, 1)/3.0 - deltaU*Y2(r+1, 1)/6.0));
    Z1.SetElement(r, 1, fabs(deltaZ)*(deltaZ/deltaU - deltaU*Z2(r, 1)/3.0 - deltaU*Z2(r+1, 1)/6.0));
  }

  // Do last control point; work backwards
  deltaU = u.GetElement(rmax-1, 1) - u.GetElement(rmax, 1);
  if(fabs(deltaU)<PRECISION)
  {
    deltaU = PRECISION;
    //throw clException("clSpline", "FirstDerivatives", "Division by zero.");
  }

  deltaX = X.GetElement(rmax-1, 1) - X.GetElement(rmax, 1);
  deltaY = Y.GetElement(rmax-1, 1) - Y.GetElement(rmax, 1);
  deltaZ = Z.GetElement(rmax-1, 1) - Z.GetElement(rmax, 1);

  X1.SetElement(rmax, 1, fabs(deltaX)*(deltaX/deltaU - deltaU*X2(rmax, 1)/3.0 - deltaU*X2(rmax-1, 1)/6.0));
  Y1.SetElement(rmax, 1, fabs(deltaY)*(deltaY/deltaU - deltaU*Y2(rmax, 1)/3.0 - deltaU*Y2(rmax-1, 1)/6.0));
  Z1.SetElement(rmax, 1, fabs(deltaZ)*(deltaZ/deltaU - deltaU*Z2(rmax, 1)/3.0 - deltaU*Z2(rmax-1, 1)/6.0));
}
void VectorCurve::loadData()
{
	int xcol = d_table->colIndex(d_x_column);
	int ycol = d_table->colIndex(title().text());
	int endXCol = d_table->colIndex(d_end_x_a);
	int endYCol = d_table->colIndex(d_end_y_m);

	int rows = abs(d_end_row - d_start_row) + 1;
    QVector<double> X(rows), Y(rows), X2(rows), Y2(rows);
    int size = 0;
	for (int i = d_start_row; i <= d_end_row; i++)
	{
		QString xval = d_table->text(i, xcol);
		QString yval = d_table->text(i, ycol);
		QString xend = d_table->text(i, endXCol);
		QString yend = d_table->text(i, endYCol);
		if (!xval.isEmpty() && !yval.isEmpty() && !xend.isEmpty() && !yend.isEmpty())
		{
			Y[size] = yval.toDouble();
			X[size] = xval.toDouble();
			Y2[size] = yend.toDouble();
			X2[size] = xend.toDouble();
			size++;
		}
	}

	if (!size)
		return;

    X.resize(size); Y.resize(size); X2.resize(size); Y2.resize(size);
	setData(X.data(), Y.data(), size);
	foreach(DataCurve *c, d_error_bars)
        c->setData(X.data(), Y.data(), size);
	setVectorEnd(X2, Y2);
}
Example #4
0
void cpp_wrap_Y2(const double* gamma_,
				   const double* vM_,
				   const unsigned int& m,
				   const unsigned int& n,
				   double* Y2_) {
	Y2(gamma_,vM_,m,n,Y2_);
}
Example #5
0
dMatrix  clSpline::GetSecondDerivatives(void)
{
  dMatrix dummy;

  if(!initialised)
  {
    Initialise();
  }

  dummy.SetNumberRows(X2.GetNumberRows());
  dummy.SetNumberColumns(3);

  for(int i=1; i<=X2.GetNumberRows(); i++)
  {
    dummy.SetElement(i, 1, fabs(X2(i, 1)) < PRECISION ? 0.0 : X2(i, 1));
    dummy.SetElement(i, 2, fabs(Y2(i, 1)) < PRECISION ? 0.0 : Y2(i, 1));
    dummy.SetElement(i, 3, fabs(Z2(i, 1)) < PRECISION ? 0.0 : Z2(i, 1));
  }

  return(dummy);
}
Example #6
0
void VectorCurve::loadData() {
  if (!plot())
    return;

  int xcol = d_table->colIndex(d_x_column);
  int ycol = d_table->colIndex(title().text());
  int endXCol = d_table->colIndex(d_end_x_a);
  int endYCol = d_table->colIndex(d_end_y_m);

  int rows = abs(d_end_row - d_start_row) + 1;
  QVector<double> X(rows), Y(rows), X2(rows), Y2(rows);
  int size = 0;
  QLocale locale = plot()->locale();
  for (int i = d_start_row; i <= d_end_row; i++) {
    QString xval = d_table->text(i, xcol);
    QString yval = d_table->text(i, ycol);
    QString xend = d_table->text(i, endXCol);
    QString yend = d_table->text(i, endYCol);
    if (!xval.isEmpty() && !yval.isEmpty() && !xend.isEmpty() &&
        !yend.isEmpty()) {
      bool valid_data = true;
      X[size] = locale.toDouble(xval, &valid_data);
      if (!valid_data)
        continue;
      Y[size] = locale.toDouble(yval, &valid_data);
      if (!valid_data)
        continue;
      X2[size] = locale.toDouble(xend, &valid_data);
      if (!valid_data)
        continue;
      Y2[size] = locale.toDouble(yend, &valid_data);
      if (valid_data)
        size++;
    }
  }

  if (!size)
    return;

  X.resize(size);
  Y.resize(size);
  X2.resize(size);
  Y2.resize(size);
  setData(X.data(), Y.data(), size);
  foreach (DataCurve *c, d_error_bars)
    c->setData(X.data(), Y.data(), size);
  setVectorEnd(X2, Y2);
}
Example #7
0
int main(int argc, char** argv) {

  int l=5;
  TinyVector<double,3> pos(0.1,0.3,-0.45), deltax(0.0001,0.0,0.0), deltay(0.0,0.0001,0.0), deltaz(0.0,0.0,0.0001), tpos, g;
  if(argc>1) l = atoi(argv[1]);
  if(argc>4) {
    pos[0] = atof(argv[2]);
    pos[1] = atof(argv[3]);
    pos[2] = atof(argv[4]);
  }

  SphericalTensor<double,TinyVector<double,3> > Y1(l,true), Y2(l,true), Yp(l,true), Ym(l,true);
  Y1.evaluate(pos);

  std::cout.setf(std::ios::scientific, std::ios::floatfield);
  for(int lm=0; lm<Y1.size(); lm++) {
    std::cout << lm << std::endl;
    std::cout << std::setw(20) << std::setprecision(12) << Y1.Ylm[lm] 
      << std::setprecision(12) << Y1.gradYlm[lm] << std::endl;
    //std::cout << std::setw(20) << std::setprecision(12) << Y2.Ylm[lm] 
    //  << std::setprecision(12) << Y2.gradYlm[lm] << std::endl;
  }

//  for(int lm=0; lm<Y1.size(); lm++) {
//    tpos = pos+deltax; Yp.evaluate(tpos);
//    tpos = pos-deltax; Ym.evaluate(tpos);
//    g[0] = (Yp.Ylm[lm]-Ym.Ylm[lm])/0.0002;
//    tpos = pos+deltay; Yp.evaluate(tpos);
//    tpos = pos-deltay; Ym.evaluate(tpos);
//    g[1] = (Yp.Ylm[lm]-Ym.Ylm[lm])/0.0002;
//    tpos = pos+deltaz; Yp.evaluate(tpos);
//    tpos = pos-deltaz; Ym.evaluate(tpos);
//    g[2] = (Yp.Ylm[lm]-Ym.Ylm[lm])/0.0002;
//    std::cout << lm << std::endl;
//    std::cout << std::setw(20) << std::setprecision(12) << Y1.Ylm[lm] 
//      << std::setprecision(12) << Y1.gradYlm[lm] - g << std::endl;
//  }
}
Example #8
0
function<RT(ArgT...)> Y2(function<RT(function<RT(ArgT...)>, ArgT...)> f) {
    return [f](ArgT&& ...arg)->RT{ return f(Y2(f), forward<ArgT>(arg) ...); };
}
Example #9
0
void bench_r2d_proj()
{
    Pt2di sz(120,50);

    Im2D_REAL8       MNT(sz.x,sz.y,0.0);
    Im2D_REAL8       X1(sz.x,sz.y,0.0);
    Im2D_REAL8       Y1(sz.x,sz.y,0.0);
    Im2D_REAL8       X2(sz.x,sz.y,0.0);
    Im2D_REAL8       Y2(sz.x,sz.y,0.0);


    ELISE_COPY(MNT.all_pts(),frandr(),MNT.out());

    ELISE_COPY
    (
        MNT.all_pts(),
        proj_cav(MNT.in(),0.5,2.0),
        Virgule(X1.out(),Y1.out())
    );

    ELISE_COPY
    (
        MNT.lmr_all_pts(Pt2di(1,0)),
        proj_cav(MNT.in(),0.5,2.0),
        Virgule(X2.out(),Y2.out())
    );

    REAL dif;

    ELISE_COPY 
    (
         MNT.all_pts(),
         Max(Abs(X1.in()-X2.in()),Abs(Y1.in()-Y2.in())),
         VMax(dif)
    );
    BENCH_ASSERT(dif<epsilon);


    ELISE_COPY
    (
        MNT.all_pts(),
        (2*PI)*phasis_auto_stereogramme(MNT.in(),10.5,2.0),
        X1.out()
    );

    ELISE_COPY
    (
        MNT.lmr_all_pts(Pt2di(1,0)),
        (2*PI)*phasis_auto_stereogramme(MNT.in(),10.5,2.0),
        X2.out()
    );

    ELISE_COPY 
    (
         MNT.all_pts(),
         Max
         (
              Abs(cos(X1.in())-cos(X2.in())),
              Abs(sin(X1.in())-sin(X2.in()))
         ),
         VMax(dif)
    );

    BENCH_ASSERT(dif<epsilon);
}
Example #10
0
double C_Rect::diagonale(void) const 
{
  double x = X2() - X1();
  double y = Y2() - Y1();
  return double(sqrt(x*x+y*y));
}
/* readonly attribute nsIDOMSVGAnimatedLength y2; */
NS_IMETHODIMP SVGLinearGradientElement::GetY2(nsIDOMSVGAnimatedLength * *aY2)
{
  *aY2 = Y2().get();
  return NS_OK;
}