当前位置: 首页>>代码示例>>C++>>正文


C++ MATRIX类代码示例

本文整理汇总了C++中MATRIX的典型用法代码示例。如果您正苦于以下问题:C++ MATRIX类的具体用法?C++ MATRIX怎么用?C++ MATRIX使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MATRIX类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: result

//////////////////////////////////////////////////////////////////////
// difference of two matrices
//////////////////////////////////////////////////////////////////////
MATRIX operator-(const MATRIX& A, const MATRIX& B)
{
  MATRIX result(A.rows(), A.cols());
  for (int y = 0; y < A.cols(); y++)
    for (int x = 0; x < A.rows(); x++)
      result(x,y) = A(x,y) - B(x,y);
  return result;
}
开发者ID:milrob,项目名称:patternformation,代码行数:11,代码来源:MATRIX.cpp

示例2: MATRIX

MATRIX *MATRIX::GetColumn(int j) {

	MATRIX *column = new MATRIX(length,1);

	for (int currRow=0;currRow<length;currRow++)
		column->Set(currRow,0,Get(currRow,j));

	return( column );
}
开发者ID:jbongard,项目名称:cords,代码行数:9,代码来源:matrix.cpp

示例3: y

//////////////////////////////////////////////////////////////////////
// Vector-matrix multiply
//////////////////////////////////////////////////////////////////////
VECTOR operator*(VECTOR& x, MATRIX& A)
{
  assert(A.rows() == x.size());

  VECTOR y(A.cols());
  for (int i = 0; i < A.cols(); i++)
    for (int j = 0; j < A.rows(); j++)
      y[i] += A(j, i) * x(j);
  return y;
}
开发者ID:milrob,项目名称:patternformation,代码行数:13,代码来源:MATRIX.cpp

示例4: RotateZ

static MATRIX RotateZ(float a){
	float cosinus=cosf(a);
	float sinus=sinf(a);
	MATRIX ret;
	ret.Identity();
	ret.m[0][0]=cosinus;
	ret.m[1][1]=cosinus;
	ret.m[0][1]=-sinus;
	ret.m[1][0]=sinus;
	return ret;
}
开发者ID:ponycalypsenow,项目名称:oldies,代码行数:11,代码来源:math.cpp

示例5: Draw

/*************
 * DESCRIPTION:   Draw a brush
 * INPUT:         disp     display class
 *                stack    matrix stack
 * OUTPUT:        none
 *************/
void BRUSH_OBJECT::Draw(DISPLAY *disp,MATRIX_STACK *stack)
{
	VECTOR size, trans;
	MATRIX m;

	switch(disp->display)
	{
		case DISPLAY_BBOX:
		case DISPLAY_WIRE:
			switch(brush->wrap)
			{
				case BRUSH_WRAP_FLAT:
					// draw a bounding box around pos
					disp->DrawBox(stack,&bboxmin,&bboxmax);
					break;
				case BRUSH_WRAP_X:
					SetVector(&size,
						(bboxmax.y - bboxmin.y) * .5f,
						bboxmax.x - bboxmin.x,
						(bboxmax.z - bboxmin.z) * .5f);
					m.SetRotZMatrix(90.f);
					stack->Push(&m);
					SetVector(&trans,
						0.f,
						- size.y * .5f,
						0.f);
					m.SetTransMatrix(&trans);
					stack->Push(&m);
					disp->DrawCylinder(stack, &size, flags);
					stack->Pop(&m);
					stack->Pop(&m);
					break;
				case BRUSH_WRAP_Y:
					SetVector(&size,
						(bboxmax.x - bboxmin.x) * .5f,
						bboxmax.y - bboxmin.y,
						(bboxmax.z - bboxmin.z) * .5f);
					SetVector(&trans,
						0.f,
						- size.y * .5f,
						0.f);
					m.SetTransMatrix(&trans);
					stack->Push(&m);
					disp->DrawCylinder(stack, &size, flags);
					stack->Pop(&m);
					break;
				case BRUSH_WRAP_XY:
					disp->DrawSphere(stack, (bboxmax.x-bboxmin.x)*.5f);
					break;
			}
			break;
	}
}
开发者ID:Kalamatee,项目名称:RayStorm,代码行数:59,代码来源:brush.cpp

示例6: main

int main(){

    freopen("in.txt","r",stdin);

    int p,q;
    int n;

    MATRIX initial;
    initial.resize(2);
    for (int i=0;i<initial.size();++i){
        initial[i].resize(2);
    }
    initial[1][0]=1;
    int kase;
    scanf("%d",&kase);

    for (int kk=1;kase--;++kk){

        scanf("%d %d %d",&p,&q,&n);
        printf("Case %d: ",kk);
        if ( n==0 ){
            printf("2\n");
        }else if ( n==1 ){
            printf("%d\n",p);
        }else if ( n==2 ){
            printf("%llu\n",LLL(p)*p-2*q);
        }
        else{
            initial[0][0]=p;
            initial[0][1]= -q;

            MATRIX result=powerMatrix( initial ,n-2 );

            LLL base1=p;
            LLL base2=LLL(p)*p-2*LLL(q);

            LLL rr=result[0][0]*(base2/2) +result[0][1]*(base1/2) ;
            rr+=result[0][0]*(base2/2) +result[0][1]*(base1/2) ;

            if ( base2 & 1 ){
                rr+=result[0][0];
            }
            if ( base1 & 1 ){
                rr+=result[0][1];
            }

            //printMatrix(result);
            printf("%llu\n",LLL(rr) );
        }
    }
    return 0;

}
开发者ID:moinulshaon,项目名称:Light-OJ,代码行数:53,代码来源:1070.cpp

示例7:

MATRIX MATRIX::operator*(MATRIX r){
	MATRIX ret;
	ret.Zero();
	for(int i=0;i<4;i++){
		for(int j=0;j<4;j++){
			ret.m[i][j]+=m[0][j]*r.m[i][0];
			ret.m[i][j]+=m[1][j]*r.m[i][1];
			ret.m[i][j]+=m[2][j]*r.m[i][2];
			ret.m[i][j]+=m[3][j]*r.m[i][3];
		}
	}
	return ret;
}
开发者ID:ponycalypsenow,项目名称:oldies,代码行数:13,代码来源:math.cpp

示例8: Filled_Volume_Helper

template<class T_SIMPLICIAL_OBJECT> typename T_SIMPLICIAL_OBJECT::SCALAR
Filled_Volume_Helper(const T_SIMPLICIAL_OBJECT& object, typename ENABLE_IF<(T_SIMPLICIAL_OBJECT::MESH::dimension==(T_SIMPLICIAL_OBJECT::VECTOR_T::m-1)),UNUSABLE>::TYPE unused=UNUSABLE())
{
    typedef typename T_SIMPLICIAL_OBJECT::SCALAR T;typedef typename T_SIMPLICIAL_OBJECT::VECTOR_T TV;//enum WORKAROUND{d=T_SIMPLICIAL_OBJECT::MESH::dimension};
    static const int d=T_SIMPLICIAL_OBJECT::MESH::dimension;
    if(d!=TV::m-1) PHYSBAM_FATAL_ERROR("only codimension 1 objects can be filled");
    const TV base=object.particles.X(object.mesh.elements(1)[1]);
    T scaled_volume=0; // (d+1)!*volume
    for(int t=1;t<=object.mesh.elements.m;t++){const VECTOR<int,d+1>& nodes=object.mesh.elements(t);
        MATRIX<T,TV::m,d+1> DX;for(int i=1;i<=nodes.m;i++) DX.Column(i)=object.particles.X(nodes[i])-base;
        scaled_volume+=DX.Parallelepiped_Measure();}
    return (T)1/FACTORIAL<d+1>::value*scaled_volume;
}
开发者ID:acrlakshman,项目名称:physbam_public,代码行数:13,代码来源:MESH_OBJECT.cpp

示例9: test2

void test2()
{
    MATRIX a = MATRIX::Random();
    for (int count = 0; count < 5; ++count) {
        clock_t start = clock();
        for (int j = 0; j < 5000; ++j) {
            a.Transposed().Translated(1, 2, 3).Transposed().Translated(3, 2, 1).Transposed().Translated(8, 9, 10)
             .Transposed().Translated(10, 9, 8).Transposed().Translated(4, 5, 6).Transposed().Translated(7, 9, 8);
        }
        clock_t finish = clock();
        std::cout << finish - start << " milliseconds" << std::endl;
    }
    std::cout << std::endl;
}
开发者ID:jsj2008,项目名称:blog-source,代码行数:14,代码来源:matrix.cpp

示例10: u

void MATRIX::Target(VECTOR v,VECTOR c,float a){
	VECTOR u(0,1,0);
	VECTOR z=v-c;z.Normalize();
	VECTOR y=u-z*Dot(u,z);y.Normalize();
	VECTOR x=Cross(y,z);
	MATRIX swp;
	swp.Identity();
	swp.m[0][0]=x.x,swp.m[0][1]=y.x,swp.m[0][2]=z.x;
	swp.m[1][0]=x.y,swp.m[1][1]=y.y,swp.m[1][2]=z.y;
	swp.m[2][0]=x.z,swp.m[2][1]=y.z,swp.m[2][2]=z.z;
	swp.m[3][0]=-Dot(c,x);
	swp.m[3][1]=-Dot(c,y);
	swp.m[3][2]=-Dot(c,z);
	*this=RotateZ(-a)*swp;
}
开发者ID:ponycalypsenow,项目名称:oldies,代码行数:15,代码来源:math.cpp

示例11: multiply

MATRIX multiply(MATRIX &a, MATRIX &b) {

    MATRIX res;
    res.resize( a.size() );
    for (int i=0;i<res.size();++i){
        res[i].resize( b[0].size() );
    }

    for (int i = 0; i < a.size(); i++)
        for (int j = 0; j < b[i].size(); j++)
            for (int k = 0; k < a[i].size() ; k++) //col of A and row of B must be same which is equal to a[i].size()
                res[i][j] = ( res[i][j] + ( ( (a[i][k] % mod ) * (b[k][j] % mod))) % mod ) %mod;

    return res;

}
开发者ID:TrojanMe,项目名称:UVa-Problems,代码行数:16,代码来源:10518.cpp

示例12: processMatrix

    void processMatrix(MATRIX & mat, int match, FuncType &processor)
    {
        set<int> row;
        set<int> col;
        for (int i = 0; i < mat.size(); ++i)
        {
            for (int j = 0; j < mat[i].size(); ++j)
            {
                if (mat[i][j] == match)
                {
                    row.insert(i);
                    col.insert(j);
                }
            }
        }


        // Process matrix
        for (int i : row)
        {
            processor(mat, i, match, ROW);
        }

        for (int i : col)
        {
            processor(mat, i, match, COL);
        }
    }
开发者ID:jjhartmann,项目名称:strident-octo-weasel,代码行数:28,代码来源:main.cpp

示例13: is_symmetric

bool is_symmetric(const MATRIX &n)
{
    unsigned int x, y;

    for (y = 0; y < n.GetHeight(); ++y)
    {
        for (x = 0; x < n.GetWidth(); ++x)
        {
            if (*n.Get(y, x) != *n.Get(x, y))
            {
                return false;
            }
        }
    }
    return true;
}
开发者ID:SwarmingSoft,项目名称:Vicsek,代码行数:16,代码来源:tests.cpp

示例14: cholesky_invert

void cholesky_invert (MATRIX &M)
{
  using namespace ublas; 
  typedef typename MATRIX::size_type size_type;
  typedef typename MATRIX::value_type value_type;

  size_type size = M.size1();

  // determine the inverse of the lower traingular matrix
  for (size_type i = 0; i < size; ++ i) {
    M(i,i) = 1 / M(i,i);

    for (size_type j = i+1; j < size; ++ j) {
      value_type elem(0);

      for (size_type k = i; k < j; ++ k) {
        elem -= M(j,k)*M(k,i);
      }
      M(j,i) = elem / M(j,j);
    }
  }

  // multiply the upper and lower inverses together
  M = prod(trans(triangular_adaptor<MATRIX,lower>(M)), triangular_adaptor<MATRIX,lower>(M));
} 
开发者ID:nelsonn3c,项目名称:monoc_slam_lsa,代码行数:25,代码来源:cholesky.hpp

示例15: concat

void MatrixApplier::concat(const MATRIX& m)
{
	float matrix[16];
	m.get4DMatrix(matrix);
	lsglMultMatrixf(matrix);
	rt->setMatrixUniform(LSGL_MODELVIEW);
}
开发者ID:exine,项目名称:lightspark,代码行数:7,代码来源:graphics.cpp


注:本文中的MATRIX类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。