Exemple #1
0
int main()
{
	int i, inp = 0;
	FILE *f1, *f2, *fkey;
	char key[100], fname[100], file_key[100];;
	char *crypt;

	f2 = fopen("output.txt","w");
	printf("Input file name: ");
	scanf("%s", fname);

	f1 = fopen(fname,"r");
	if (f1 == NULL) {
		printf("file not found\n");
	 	return 0;
	}

	inp = input();
	printf("\nINP = %d\n", inp);
	char *text = reading(f1);
	switch (inp)
	{
		case 1:
			printf("Ключ (слово до 99 букв): ");
			scanf("%s",key);
			vij(key, f1, f2);
			break;
	//	case 2:
	//		break;
		case 3:
			i = vernam_input(file_key);
			fkey = fopen(file_key, "r+");
			char *k = reading(fkey);
			if (i == 1) {
				k = realloc(k, strlen(text) * sizeof(char));
				crypt = vernam_crypt(text, k);
				output(k, fkey);
			}
			else if (i == 2)
				crypt = vernam_decrypt(text, k);
			else {
				printf("Неправильный ввод.\n");
				exit(EXIT_FAILURE);
			}
			if (crypt == NULL) {
				printf("Ошибка. Длина ключа не соответствует длине текста.\n");
				exit(EXIT_FAILURE);
			}
		break;
	//	case 4:
		//	break;
		default:
			printf( "Неправильный ввод.\n" );
	}
	output(crypt, f2);
	printf("Ваш результат находится в файле output.txt \n");
	fclose(f1);
	free(text);
	return 0;
}
Exemple #2
0
void QHull3d::createInitialTetrahedron()
{
	float d;
	float dmax;

	int epidx[6];
	int tetraidx[4];

	// Get extreme points (EP)
	for (int i = 0; i < 6; ++i)
		epidx[i] = -1;

	for (int i = 0; i < _pointcount; ++i)
	{
		const gk::Point& p = _points[i];

		if (epidx[0] < 0 || p.x < _points[epidx[0]].x)
			epidx[0] = i;
		if (epidx[1] < 0 || p.x > _points[epidx[1]].x)
			epidx[1] = i;

		if (epidx[2] < 0 || p.y < _points[epidx[2]].y)
			epidx[2] = i;
		if (epidx[3] < 0 || p.y > _points[epidx[3]].y)
			epidx[3] = i;

		if (epidx[4] < 0 || p.z < _points[epidx[4]].z)
			epidx[4] = i;
		if (epidx[5] < 0 || p.z > _points[epidx[5]].z)
			epidx[5] = i;
	}

	// Find the most distant EP pair to build base triangle's first edge
	dmax = 0.f;

	for (int i = 0; i < 5; ++i)
	{
		for (int j = i + 1; j < 6; ++j)
		{
			gk::Vector vij(_points[epidx[i]], _points[epidx[j]]);

			if ((d = vij.LengthSquared()) > dmax)
			{
				tetraidx[0] = epidx[i];
				tetraidx[1] = epidx[j];

				dmax = d;
			}
		}
	}

	// Find the most distant EP from the first edge's support line to complete the base triangle
	dmax = 0.f;
	tetraidx[2] = -1;

	const gk::Point& t0 = _points[tetraidx[0]];
	gk::Vector t01 = gk::Normalize(gk::Vector(t0, _points[tetraidx[1]]));

	for (int i = 0; i < 6; ++i)
	{
		if (epidx[i] == tetraidx[0] || epidx[i] == tetraidx[1])
			continue;

		gk::Vector t0i(t0, _points[epidx[i]]);
		float pprojlength = gk::Dot(t0i, t01);
		d = t0i.LengthSquared() - (pprojlength * pprojlength);

		if (d > dmax)
		{
			tetraidx[2] = epidx[i];

			dmax = d;
		}
	}

	// Special case where there are only 2 extreme points => Pick any remaining point
	if (tetraidx[2] < 0)
	{
		for (int i = 0; i < _pointcount; ++i)
		{
			if (i != tetraidx[0] && i != tetraidx[1])
			{
				tetraidx[2] = i;
				break;
			}
		}
	}

	// Find the most distant point from the base triangle within the point cloud to complete the initial tetrahedron
	dmax = 0.f;
	HEFace* tetrabase = createFace(tetraidx[0], tetraidx[1], tetraidx[2]);

	for (int i = 0; i < _pointcount; ++i)
	{
		if (i == tetraidx[0] || i == tetraidx[1] || i == tetraidx[2])
			continue;

		//if (fabs(d = tetrabase->distance(_points[i])) > fabs(dmax))
		if (fabs(d = tetrabase->distance(_points[i])) >= fabs(dmax))
		{
			tetraidx[3] = i;

			dmax = d;
		}
	}

	// Coplanarity detection
	if (dmax == 0)
	{
		initialize2d();

		return;
	}

	// Reverse the base triangle if not counter clockwise oriented according to the tetrahedron outer surface
	if (dmax > 0)
		tetrabase->reverse();

	// Complete the tetrahedron's mesh
	std::vector<HEFace*> tetrafaces = extrudeOut(tetrabase, tetraidx[3]);
	tetrafaces.insert(tetrafaces.begin(), tetrabase);

	// Assign remaining points to their corresponding face
	for (int i = 0; i < _pointcount; ++i)
	{
		if (i == tetraidx[0] || i == tetraidx[1] || i == tetraidx[2] || i == tetraidx[3])
			continue;

		for (int f = 0; f < (int)tetrafaces.size(); ++f)
		{
			if (tetrafaces[f]->tryAssignVertex(_vertices[i].get()))
				break;
		}
	}

	//! Add the tetrahedron's not empty faces to the processing stack
	for (int i = 0; i < (int)tetrafaces.size(); ++i)
		if (!tetrafaces[i]->vertices.empty())
			_processingfaces.push(tetrafaces[i]);

	// Store hull first vertex
	_hull = _vertices[tetraidx[0]].get();

	//////////////////////////////////////////////////////////////////////////
	// ToDo JRA: Remove this test code

	assertManifoldValidity(_hull);
}
void IterativeImpulseBasedConstraintSolverStrategy::computeConstraintsANDJacobian(std::vector<std::unique_ptr<IConstraint> >& c, const Mat<float>& q, const Mat<float>& qdot, const SparseMat<float>& invM)
{
	//-------------------------------------
	//-------------------------------------
	//-------------------------------------
	
	size_t size = c.size();
	int n = sim->simulatedObjects.size();
	float baumgarteBAS = 0.0f;//1e-1f;
	float baumgarteC = -2e0f;
	float baumgarteH = 0.0f;//1e-1f;
	
	//---------------
	//	RESETTING :
	constraintsC.clear();
	constraintsJacobians.clear();
	constraintsOffsets.clear();
	constraintsIndexes.clear();
	constraintsInvM.clear();
	constraintsV.clear();
	//----------------------
	
	if( size > 0)
	{
		
		for(int k=0;k<size;k++)
		{
			int idA = ( c[k]->rbA.getID() );
			int idB = ( c[k]->rbB.getID() );
			std::vector<int> indexes(2);
			//indexes are set during the creation of the simulation and they begin at 0.
			indexes[0] = idA;
			indexes[1] = idB;
			
			constraintsIndexes.push_back( indexes );
			
			//---------------------------
			//Constraint :
			c[k]->computeJacobians();
			
			
			Mat<float> tJA(c[k]->getJacobianA());
			Mat<float> tJB(c[k]->getJacobianB());
		
			
			Mat<float> tC(c[k]->getConstraint());
			constraintsC.push_back( tC );
	
			int nbrlineJ = tJA.getLine();
			Mat<float> JacobianAB( operatorL(tJA, tJB)  );
			constraintsJacobians.push_back( JacobianAB );
			
			//----------------------------------------
			//BAUMGARTE STABILIZATION
			//----------------------------------------
			//Contact offset :
			if( c[k]->getType() == CTContactConstraint)
			{
				//----------------------------------------
				//SLOP METHOD :
				/*
				float slop = 1e0f;
				float pdepth = ((ContactConstraint*)(c[k].get()))->penetrationDepth;
				std::cout << " ITERATIVE SOLVER :: CONTACT : pDepth = " << pdepth << std::endl;
				tC *= baumgarteC/this->dt * fabs_(fabs_(pdepth)-slop);			
				*/
				//----------------------------------------
				
				//----------------------------------------
				//DEFAULT METHOD :
				tC *= baumgarteC/this->dt;
				//----------------------------------------
				
				//----------------------------------------
				//METHOD 2 :
				/*
				float restitFactor = ( (ContactConstraint*) (c[k].get()) )->getRestitutionFactor();
				std::cout << " ITERATIVE SOLVER :: CONTACT : restitFactor = " << restitFactor << std::endl;
				Mat<float> Vrel( ( (ContactConstraint*) (c[k].get()) )->getRelativeVelocity() );
				Mat<float> normal( ( (ContactConstraint*) (c[k].get()) )->getNormalVector() );
				std::cout << " ITERATIVE SOLVER :: CONTACT : Normal vector : " << std::endl;
				transpose(normal).afficher();
				tC +=  restitFactor * transpose(Vrel)*normal; 
				*/
				//----------------------------------------
				
				std::cout << " ITERATIVE SOLVER :: CONTACT : Contact Constraint : " << std::endl;
				transpose(tC).afficher();
				std::cout << " ITERATIVE SOLVER :: CONTACT : Relative Velocity vector : " << std::endl;
				transpose(( (ContactConstraint*) (c[k].get()) )->getRelativeVelocity()).afficher();
				//std::cout << " ITERATIVE SOLVER :: CONTACT : First derivative of Contact Constraint : " << std::endl;
				//(transpose(tJA)*).afficher();
					
			}
			//BAS JOINT :
			if( c[k]->getType() == CTBallAndSocketJoint)
			{
				tC *= baumgarteBAS/this->dt;
			}
			
			//HINGE JOINT :
			if( c[k]->getType() == CTHingeJoint)
			{
				tC *= baumgarteH/this->dt;
			}
			
			//BAUMGARTE OFFSET for the moments...
			constraintsOffsets.push_back( tC );
			
			//----------------------------------------
			//----------------------------------------
			
			
			//-------------------
			//	invM matrixes :
			Mat<float> invmij(0.0f,12,12);
			for(int k=0;k<=1;k++)
			{
				for(int i=1;i<=6;i++)
				{
					for(int j=1;j<=6;j++)
					{
						invmij.set( invM.get( indexes[k]*6+i, indexes[k]*6+j), k*6+i,k*6+j);
						
					}
				}
			}
			
			constraintsInvM.push_back( invmij);
			
			
			//-------------------
			//	Vdot matrixes :
			Mat<float> vij(0.0f,12,1);
			for(int k=0;k<=1;k++)
			{
				for(int i=1;i<=6;i++)
				{
					vij.set( qdot.get( indexes[k]*6+i, 1), k*6+i,1);
				}
			}
			
			constraintsV.push_back( vij);
			
			
			
		}
		
	}	
}
Exemple #4
0
EvolDC1Buras::EvolDC1Buras(unsigned int dim_i, schemes scheme, orders order, const StandardModel& model) 
:           RGEvolutor(dim_i, scheme, order), model(model),
            v(dim_i,0.), vi(dim_i,0.), js(dim_i,0.), h(dim_i,0.), gg(dim_i,0.), s_s(dim_i,0.),
            jssv(dim_i,0.), jss(dim_i,0.), jv(dim_i,0.), vij(dim_i,0.), e(dim_i,0.), dim(dim_i)  
{
    
    /*magic numbers a & b */
    
    for(int L=2; L>-1; L--){
        
    /* L=2 --> u,d,s,c (nf=4)  L=1 --> u,d,s,c,b (nf=5) L=0 --> u,d,s,c,b,t (nf=6)*/
        
    nu = L;  nd = L;
    if(L == 1){nd = 3; nu = 2;} 
    if(L == 0){nd = 3; nu = 3;}
    
    AnomalousDimension_DC1_Buras(LO,nu,nd).transpose().eigensystem(v,e);
    vi = v.inverse();
    for(unsigned int i = 0; i < dim; i++){
       a[L][i] = e(i).real();
       for (unsigned int j = 0; j < dim; j++) {
           for (unsigned int k = 0; k < dim; k++)  {
                b[L][i][j][k] = v(i, k).real() * vi(k, j).real();
               }
           }
       }
    
    // LO evolutor in the standard basis
    
    gg = vi * AnomalousDimension_DC1_Buras(NLO,nu,nd).transpose() * v;
    double b0 = model.Beta0(6-L);
    double b1 = model.Beta1(6-L);
    for (unsigned int i = 0; i < dim; i++){
        for (unsigned int j = 0; j < dim; j++){
            s_s.assign( i, j, (b1 / b0) * (i==j) * e(i).real() - gg(i,j));    
            if(fabs(e(i).real() - e(j).real() + 2. * b0)>0.00000000001){
                h.assign( i, j, s_s(i,j) / (2. * b0 + e(i) - e(j)));
                }
            }
        }
    js = v * h * vi;
    jv = js * v;
    vij = vi * js;
    jss = v * s_s * vi;
    jssv = jss * v;        
    for (unsigned int i = 0; i < dim; i++){
        for (unsigned int j = 0; j < dim; j++){
            if(fabs(e(i).real() - e(j).real() + 2. * b0) > 0.00000000001){
                for(unsigned int k = 0; k < dim; k++){
                        c[L][i][j][k] = jv(i, k).real() * vi(k, j).real();
                        d[L][i][j][k] = -v(i, k).real() * vij(k, j).real();
                        }
                    }
            else{    
                for(unsigned int k = 0; k < dim; k++){
                   c[L][i][j][k] = (1./(2. * b0)) * jssv(i, k).real() * vi(k, j).real();
                   d[L][i][j][k] = 0.;
                   }   
                }
            }
        }
    }
}