Skip to content
Snippets Groups Projects
Commit bf26daa2 authored by ExtraDev's avatar ExtraDev
Browse files

create regroupe of groups function

parent 6e02e917
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -105,6 +105,20 @@ void create_group_random(group_t *group, point_t* points, int n_points, int n_gr
free(tmp);
}
point_t* group(group_t *group, int a, int b) {
int nb_points = (int)(group->n_points/group->n_groups) * 2; // 30 / 3 * 2 = 20
point_t* result = malloc(sizeof(point_t) * nb_points);
for (int i = 0; i < nb_points/2; i++)
{
result[i] = group->points[a][i];
result[nb_points/2+i] = group->points[b][i];
}
return result;
}
void print_group(group_t *group){
for (int i = 0; i < group->n_groups; i++)
{
......
......@@ -49,6 +49,7 @@ double fd(vector_t x); // test
// Gestion des groupes
void create_group(group_t *group, point_t* points, int n_points, int n_groups);
void create_group_random(group_t *group, point_t* points, int n_points, int n_groups);
point_t* group(group_t *group, int a, int b);
void print_group(group_t *group);
void destroy_group(group_t *group);
......
......@@ -59,6 +59,14 @@ int main(int argc, char* argv[]) {
create_group_random(&groups, points, nb_points, 3);
print_group(&groups);
// Exemple of grouping two groups
point_t* yes = group(&groups, 0, 1);
for (int i = 0; i < 20; i++)
{
printf("%f, %f\n", yes[i].x, yes[i].y);
}
vector_t resAB = descente_radian(points, nb_points);
point_t* AB = malloc(sizeof(point_t));
*AB = (point_t){resAB.x, resAB.y};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment