*/
inline void Body_Force(Body * a, Body * b)
{
+ float distance;
+ float con;
+ float gd;
//Calculate distance between a and b
distance = 0.0;
for (unsigned i = 0; i < DIMENSIONS; ++i)
FILE * file;
file = fopen(fileName, "rt");
+
+ if (file == NULL)
+ {
+ fprintf(stderr, "%s\n", fileName);
+ perror("Couldn't open file");
+ exit(EXIT_FAILURE);
+ }
+
s->N = atoi(fgets(line, LINE_SIZE, file));
s->body = (Body*) calloc((size_t)s->N, sizeof(Body));
s->steps = 0;
}
return result;
}
+
+/**
+ * @function System_Random
+ * @purpose Randomly generate initial body field
+ * @param s - The system
+ * @param n - Number of bodies
+ */
+void System_Random(System * s, int n)
+{
+ srand(time(NULL));
+ s->N = (unsigned)n;
+ s->body = (Body*) calloc((size_t)s->N, sizeof(Body));
+ s->steps = 0;
+
+ s->body[0].mass = 1e11;
+
+ for (unsigned a = 1; a < s->N; ++a)
+ {
+ s->body[a].mass = 1e7;
+ for (unsigned i = 0; i < DIMENSIONS; ++i)
+ {
+ s->body[a].x[i] = -10000 + rand() % 20000;
+ s->body[a].v[i] = -2 + rand() % 4;
+ }
+ s->body[a].v[2] = 0;
+ s->body[a].x[2] = 0; //set z to zero; force in plane
+
+ }
+}