Commit 5063ae63 authored by ewen.madec's avatar ewen.madec

Gabriel Graph + minimum distance btw nodes

parent f6ac9d3d
......@@ -87,7 +87,7 @@ void Panel_drawNode(Panel * self, Node * n)
Vector2 screenPosition= Panel_pixelFromPosition(self, &(n->position) );
DrawCircleV(screenPosition, 24, n->color);
DrawCircleV(screenPosition, 20, RAYWHITE);
char * soldierText = malloc(sizeof(int));
char * soldierText = malloc(20*sizeof(char));
sprintf(soldierText, "%d", n->soldiers + n->soldiersToAdd);
DrawText(soldierText, (int)screenPosition.x - MeasureText(soldierText, 20)/2, (int)screenPosition.y, 20, n->color);
}
......
......@@ -11,7 +11,6 @@
#include "raylib.h"
double randfrom(double min, double max)
{
double range = (max - min);
......@@ -19,49 +18,88 @@ double randfrom(double min, double max)
return min + (rand() / div);
}
double dist(Node node1, Node node2){
return(sqrt( (node2.position.x - node1.position.x)*(node2.position.x - node1.position.x) + (node2.position.y - node1.position.y)*(node2.position.y - node1.position.y) ));
double dist(Vector2 vector1, Vector2 vector2)
{
return (sqrt((vector2.x - vector1.x) * (vector2.x - vector1.x) + (vector2.y - vector1.y) * (vector2.y - vector1.y)));
}
double distNode(Node node1, Node node2)
{
return (dist(node1.position, node2.position));
}
void Random_map(NetWorld * world)
void Random_map(NetWorld *world)
{
int nbNode = world->size;
float randomX, randomY;
/* Intializes random number generator */
/* Intializes random number generator */
srand(time(NULL));
/* Print 5 random numbers from -15.00 to 15.00 */
for( int i = 0 ; i < nbNode ; i++ ) {
double randomX = randfrom(-15.0, 15.0);
double randomY = randfrom(-15.0, 15.0);
char * name;
name= malloc(sizeof(int));
/* Generate nbNode*2 random numbers from -15.00 to 15.00 */
for (int i = 0; i < nbNode; i++)
{
if (i > 0)
{
bool continueLoop = true;
while (continueLoop)
{
continueLoop = false;
randomX = randfrom(-30.0, 30.0);
randomY = randfrom(-30.0, 30.0);
Vector2 newPosition = (Vector2){randomX, randomY};
for (int j = 0; j < i; j++)
{
printf("positionComparee %d %f\n", j, dist(world->nodes[j].position, newPosition));
if (dist(world->nodes[j].position, newPosition) < 8.0)
{
continueLoop = true;
}
}
}
//randomX = randfrom(-15.0, 15.0);
//randomY = randfrom(-15.0, 15.0);
char *name;
name = malloc(20*sizeof(char));
sprintf(name, "name : %d", i);
Node_set(&(world->nodes[i]), (Vector2){randomX, randomY}, RED, name);
}
else
{
randomX = randfrom(-15.0, 15.0);
randomY = randfrom(-15.0, 15.0);
char *name;
name = malloc(20*sizeof(char));
sprintf(name, "name : %d", i);
Node_set( &(world->nodes[i]), (Vector2){randomX, randomY}, RED, name);
Node_set(&(world->nodes[i]), (Vector2){randomX, randomY}, RED, name);
printf("%f\n", randomX);
printf("%f\n", randomY);
}
}
//Gabriel graph sort
for( int i = 0; i <nbNode-1 ; i++){
for( int j = i+1; j <nbNode ; j++){
for (int i = 0; i < nbNode - 1; i++)
{
for (int j = i + 1; j < nbNode; j++)
{
int compteurPointDansLeCercle = 0;
float xm = 0.5*(world->nodes[i].position.x + world->nodes[j].position.x);
float ym = 0.5*(world->nodes[i].position.y + world->nodes[j].position.y);
float distCenterOfij = sqrt((xm - world->nodes[i].position.x)*(xm - world->nodes[i].position.x) + (ym - world->nodes[i].position.y)*(ym - world->nodes[i].position.y));
printf("xm : %f\n", xm);
printf("ym : %f\n", ym);
printf("distCenterOfij : %f\n", distCenterOfij);
printf("dist %d%d : %f\n", i ,j ,dist((world->nodes[i]),world->nodes[j]));
for(int k = 0 ; k < nbNode ; k++){
printf(" dist center - Node k %f\n", sqrt((world->nodes[k].position.x - xm)*(world->nodes[k].position.x - xm) + (world->nodes[k].position.y - ym)*(world->nodes[k].position.y - ym)));
if( sqrt((world->nodes[k].position.x - xm)*(world->nodes[k].position.x - xm) + (world->nodes[k].position.y - ym)*(world->nodes[k].position.y - ym)) < distCenterOfij -0.05){
compteurPointDansLeCercle ++;
float xm = 0.5 * (world->nodes[i].position.x + world->nodes[j].position.x);
float ym = 0.5 * (world->nodes[i].position.y + world->nodes[j].position.y);
Vector2 M = {xm, ym};
float distNodeCenterOfij = dist(world->nodes[i].position, M);
//printf("xm : %f\n", xm);
//printf("ym : %f\n", ym);
//printf("distNodeCenterOfij : %f\n", distNodeCenterOfij);
printf("distNode %d%d : %f\n", i, j, distNode((world->nodes[i]), world->nodes[j]));
for (int k = 0; k < nbNode; k++)
{
//printf(" distNode center - Node k %f\n", dist(world->nodes[k].position, M));
if (dist(world->nodes[k].position, M) < distNodeCenterOfij - 0.05)
{
compteurPointDansLeCercle++;
}
}
printf("compteurPointDansLeCercle : %i\n", compteurPointDansLeCercle);
if(compteurPointDansLeCercle == 0){
//printf("compteurPointDansLeCercle : %i\n", compteurPointDansLeCercle);
if (compteurPointDansLeCercle == 0)
{
NetWorld_biconnect(world, i, j);
}
}
}
}
\ No newline at end of file
......@@ -8,6 +8,7 @@ void Random_map(NetWorld * world);
double randfrom(double min, double max);
double dist(Node node1, Node node2);
double dist(Vector2 vector1, Vector2 vector2);
double distNode(Node node1, Node node2);
#endif
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment