Exemple #1
0
void init()
{
  int i;
  float red,green,blue;
  for(i=0;i<5;i++)
    {
      if(i==0)
	{
	  red=1;green=0;blue=0;
	}
      else if(i==1)
	{
	   red=1;green=1;blue=0;
	}
      else if(i==2)
	{
	   red=1;green=0;blue=1;
	}
      
      else if(i==3)
	{
	   red=0;green=0;blue=1;
	}
      else 
	{
	   red=0.1;green=0.6;blue=0.1;
	}
      cir[i].red=red;cir[i].g=green;cir[i].b=blue;
      cir[i].rr=randomfloat(20,80);
      cir[i].x=randomfloat(15,440);
      cir[i].y=randomm(480,700);
    }
}
void translate(int size, float G1[size][2], float G2[size][2], float centerX, float centerY){

	float distortionX;
	float distortionY;
	distortionX = randomfloat();
	distortionY = randomfloat();
	for(int i=0; i < size; i++){
		G2[i][0] = distortionX + G1[i][0];
		G2[i][1] = distortionY + G1[i][1];
	}

} //end of function
void makeAdjacency(int size, float adjacent[size][size], int edges){

	float temp;
	float p = (float)edges / ((((float)size * (float)size)/2) - ((float)size/2));
//	printf("probability = %f\n", p);
	int edgeCount = 0;
//the adjacency matrix will be symmetric therefore its only neccessary to 
//loop through half of the elements

//we assume there are no loops in this graph
	while(edgeCount != edges){

		for(int i = 1; i < size; i++){
			for(int j = 0; j < i; j++){

				temp = fabs(randomfloat());

				if(temp < p){
					if(adjacent[i][j] != 1){

						adjacent[i][j] = 1;
						adjacent[j][i] = 1;
						edgeCount++;
						if(edgeCount == edges)
							return;

					} //adjacent...
				} //temp<p

			} // j
		} // i

	} //while loop

} //end of function
//function returns a random float value in the interval [0, 2PI]
float randomfloatAngle(){

	//generate random float between 0 and 1
	float r = fabs(randomfloat());

	//scale to the 0 to 2PI range
	r *= (2*PI);

	return r;
} //end of function
Exemple #5
0
void init1(int i)
{
  cir[i].rr=randomfloat(20,80);
  cir[i].x=randomfloat(15,440);
  cir[i].y=randomm(480,700);
}
void main(){

	srand(time(0));

//create random set of points
	int size = TEST_SIZE;
	float G1[size][2];
	for(int i=0; i < size; i++){
		G1[i][0] = randomfloat()/10;
		G1[i][1] = randomfloat()/10;
	}
	//printMatrix(size, 2, G1);

//create adjacency matrix to determine where edges exist
	float adjacent[size][size];
	zeros(size, size, adjacent);
	int edges = 6;
	makeAdjacency(size, adjacent, edges);

	//printf("Adjacency Matrix\n");
	//printMatrix(size, size, adjacent);


//copy original set of points for distortion
	float G2[size][2];
	for(int i=0; i < size; i++){
		G2[i][0] = G1[i][0];
		G2[i][1] = G1[i][1];
	}

//distort the graph for testing purposes
	graphDistortion(size, G1, G2, 0, 0);
	//printMatrix(size, 2, G2);

//calculate the distances to each neighbor
	float neighborDist1[size][size], neighborDist2[size][size];
	neighborDistances(size, G1, neighborDist1, adjacent);
	neighborDistances(size, G2, neighborDist2, adjacent);

	//printf("neighbor Distances 1\n");
	//printMatrix(size, size, neighborDist1);

	//printf("neighbor distances 2\n");
	//printMatrix(size, size, neighborDist2);

	int size2;
	size2 = (size*size)/2 - (size/2);


	float simMatrix[size2][size2];
	zeros(size2, size2, simMatrix);

//check to see if the graphs are the same
	similarity(size, size2, edges, neighborDist1, neighborDist2, simMatrix);
	//printf("Similarity Scores\n");
	//printMatrix(size2, size2, simMatrix);

	  float X[size][size];
	  float Z[size][size];
	  float Y[size][size];
	  graphMatching(size,neighborDist1,size,neighborDist2, 0.001,size,X,Z,Y);

	  printf("X(hard):\n");
	  printMatrix(size, size, X);
	  printf("Z(soft):\n");
	  printMatrix(size, size, Z);
	  printf("Y(debug):\n");
	  printMatrix(size, size, Y);



}
Exemple #7
0
Vector3 ParticleSystemManager::randomVector3()
{
	return Vector3(randomfloat(), randomfloat(), randomfloat());
}