Exemplo n.º 1
0
    inline
    int solve (int sys, int n,
               int const* Ap, int const* Ai, traits::complex_d const* Ax,
               traits::complex_d* X, traits::complex_d const* B,
               void *Numeric, double const* Control, double* Info)
    {
      int nnz = Ap[n];
      bindings::detail::array<double> Axr (nnz);
      if (!Axr.valid()) return UMFPACK_ERROR_out_of_memory;
      bindings::detail::array<double> Axi (nnz);
      if (!Axi.valid()) return UMFPACK_ERROR_out_of_memory;
      traits::detail::disentangle (Ax, Ax+nnz,
                                   Axr.storage(), Axi.storage());
      bindings::detail::array<double> Br (n);
      if (!Br.valid()) return UMFPACK_ERROR_out_of_memory;
      bindings::detail::array<double> Bi (n);
      if (!Bi.valid()) return UMFPACK_ERROR_out_of_memory;
      traits::detail::disentangle (B, B+n,
                                   Br.storage(), Bi.storage());
      bindings::detail::array<double> Xr (n);
      if (!Xr.valid()) return UMFPACK_ERROR_out_of_memory;
      bindings::detail::array<double> Xi (n);
      if (!Xi.valid()) return UMFPACK_ERROR_out_of_memory;

      int status = umfpack_zi_solve (sys, Ap, Ai,
                                     Axr.storage(), Axi.storage(),
                                     Xr.storage(), Xi.storage(),
                                     Br.storage(), Bi.storage(),
                                     Numeric, Control, Info);
      if (status != UMFPACK_OK) return status;
      traits::detail::interlace (Xr.storage(), Xr.storage() + n,
                                 Xi.storage(), X);
      return status;
    }
vector<Coord> GlCubicBSplineInterpolation::constructInterpolatingCubicBSpline(const vector<Coord> &pointsToInterpolate) {
  vector<Coord> Ai(pointsToInterpolate.size());
  vector<float> Bi(pointsToInterpolate.size());
  vector<Coord> di(pointsToInterpolate.size());
  di[0] = (pointsToInterpolate[1] - pointsToInterpolate[0]) / 3.0f;
  di[pointsToInterpolate.size() - 1] = (pointsToInterpolate[pointsToInterpolate.size()-1] - pointsToInterpolate[pointsToInterpolate.size()-2]) / 3.0f;
  Bi[1] = -0.25f;
  Ai[1] = (pointsToInterpolate[2] - pointsToInterpolate[0] - di[0]) / 4.0f;

  for (size_t i = 2; i < pointsToInterpolate.size() - 1; ++i) {
    Bi[i] = -1.0f /(4.0f + Bi[i-1]);
    Ai[i] = Coord(-(pointsToInterpolate[i+1] - pointsToInterpolate[i-1] - Ai[i-1])*Bi[i]);
  }

  for (size_t i = pointsToInterpolate.size() - 2; i > 0; --i) {
    di[i] = Ai[i] + di[i+1]*Bi[i];
  }

  vector<Coord> bSplineControlPoints;
  bSplineControlPoints.push_back(pointsToInterpolate[0]);
  bSplineControlPoints.push_back(pointsToInterpolate[0]+di[0]);

  for (size_t i = 1 ; i < pointsToInterpolate.size() - 1 ; ++i) {
    bSplineControlPoints.push_back(pointsToInterpolate[i]-di[i]);
    bSplineControlPoints.push_back(pointsToInterpolate[i]);
    bSplineControlPoints.push_back(pointsToInterpolate[i]+di[i]);
  }

  bSplineControlPoints.push_back(pointsToInterpolate[pointsToInterpolate.size() - 1]-di[pointsToInterpolate.size() - 1]);
  bSplineControlPoints.push_back(pointsToInterpolate[pointsToInterpolate.size() - 1]);
  return bSplineControlPoints;
}
Exemplo n.º 3
0
void Rubik::turnCubeLeft() { //White to green
	F(false);
	Bi(false);
	this->shift(this->middle, 3, 2, 4, 1);
	this->shift(this->edges, 6, 20, 9, 19);
	this->shift(this->edges, 7, 18, 8, 21);

	std::map<std::string, std::string> tempMap(movesDictionary);
	//Dictionary

	movesDictionary[_R] = tempMap[_U];
	movesDictionary[_Ri] = tempMap[_Ui];
	movesDictionary[_R2] = tempMap[_U2];
	movesDictionary[_L] = tempMap[_D];
	movesDictionary[_Li] = tempMap[_Di];
	movesDictionary[_L2] = tempMap[_D2];
	movesDictionary[_U] = tempMap[_L];
	movesDictionary[_Ui] = tempMap[_Li];
	movesDictionary[_U2] = tempMap[_L2];
	/*movesDictionary[_B] = movesDictionary[_B];
	movesDictionary[_Bi] = movesDictionary[_Bi];
	movesDictionary[_B2] = movesDictionary[_B2];
	movesDictionary[_F] = movesDictionary[_F];
	movesDictionary[_Fi] = movesDictionary[_Fi];
	movesDictionary[_F2] = movesDictionary[_F2];*/
	movesDictionary[_D] = tempMap[_R];
	movesDictionary[_Di] = tempMap[_Ri];
	movesDictionary[_D2] = tempMap[_R2];

}
Exemplo n.º 4
0
void Cube::RotateClockwise()
{
    F();
    SaveState();
    subCubes[0][0][1] = ROTATE_CLK(oldSubCubes[2][0][1]);
    subCubes[1][0][1] = ROTATE_CLK(oldSubCubes[2][1][1]);
    subCubes[2][0][1] = ROTATE_CLK(oldSubCubes[2][2][1]);
    subCubes[0][1][1] = ROTATE_CLK(oldSubCubes[1][0][1]);
    subCubes[1][1][1] = ROTATE_CLK(oldSubCubes[1][1][1]);
    subCubes[2][1][1] = ROTATE_CLK(oldSubCubes[1][2][1]);
    subCubes[0][2][1] = ROTATE_CLK(oldSubCubes[0][0][1]);
    subCubes[1][2][1] = ROTATE_CLK(oldSubCubes[0][1][1]);
    subCubes[2][2][1] = ROTATE_CLK(oldSubCubes[0][2][1]);
    Bi();
}
Exemplo n.º 5
0
Arquivo: Bezier.cpp Projeto: Neolus/C
/*****定义函贝塞尔插值函数*********/
float bezier(float *a,float t,int n)  //a为输入的控制点数据,t为0到1的一个值,与x对应,n为输入点的个数
{
	n=n-1;  //最高阶为点数减1
	float Bi(float t,int i,int n); //函数声明,Bi为具体i、n对应的伯恩斯坦多项式的值

	float s=0; // 初始化求和项
	int i;

	for (i=0;i<=n;i++)
	{
		s=s+Bi(t,i,n)*a[i]; //贝塞尔曲线公式
	}

	return (s);  //返回最后的计算结果

}
Exemplo n.º 6
0
    inline
    int scale (int n, traits::complex_d* X,
               traits::complex_d const* B, void* Numeric)
    {
      bindings::detail::array<double> Br (n);
      if (!Br.valid()) return UMFPACK_ERROR_out_of_memory;
      bindings::detail::array<double> Bi (n);
      if (!Bi.valid()) return UMFPACK_ERROR_out_of_memory;
      traits::detail::disentangle (B, B+n,
                                   Br.storage(), Bi.storage());
      bindings::detail::array<double> Xr (n);
      if (!Xr.valid()) return UMFPACK_ERROR_out_of_memory;
      bindings::detail::array<double> Xi (n);
      if (!Xi.valid()) return UMFPACK_ERROR_out_of_memory;

      int status = umfpack_zi_scale (Xr.storage(), Xi.storage(),
                                     Br.storage(), Bi.storage(),
                                     Numeric);
      if (status != UMFPACK_OK) return status;
      traits::detail::interlace (Xr.storage(), Xr.storage() + n,
                                 Xi.storage(), X);
      return status;
    }
Exemplo n.º 7
0
void Cube::DoMethod(CubeRotateMethod method)
{
    switch (method)
    {
    case ROTATE_NONE:
    case ROTATE_NONEi:
        break;
    case ROTATE_FRONT:
        F();
        break;
    case ROTATE_BACK:
        B();
        break;
    case ROTATE_LEFT:
        L();
        break;
    case ROTATE_RIGHT:
        R();
        break;
    case ROTATE_UP:
        U();
        break;
    case ROTATE_DOWN:
        D();
        break;
    case ROTATE_FRONTi:
        Fi();
        break;
    case ROTATE_BACKi:
        Bi();
        break;
    case ROTATE_LEFTi:
        Li();
        break;
    case ROTATE_RIGHTi:
        Ri();
        break;
    case ROTATE_UPi:
        Ui();
        break;
    case ROTATE_DOWNi:
        Di();
        break;
    case ROTATE_WHOLEX:
        RotateUp();
        break;
    case ROTATE_WHOLEY:
        RotateLeft();
        break;
    case ROTATE_WHOLEZ:
        RotateClockwise();
        break;
    case ROTATE_WHOLEXi:
        RotateDown();
        break;
    case ROTATE_WHOLEYi:
        RotateRight();
        break;
    case ROTATE_WHOLEZi:
        RotateCounterClockwise();
        break;
    default:
        break;
    }
}