Beispiel #1
0
double triangle_area(double *p1, double *p2, double *p3)
{
    double 	aa, bb, cc,
            s, S, q;

    aa=calc_dis(p1, p2);
    bb=calc_dis(p2, p3);
    cc=calc_dis(p3, p1);

    s = (aa+bb+cc)/2;
    q = s*(s-aa)*(s-bb)*(s-cc);
    if( q < 0.0 ) q = 0.0;

    S = sqrt(q);

    return S;
}
Beispiel #2
0
static void populate_matrix(struct tspfile *map, double ** matrix) {
	register int i, y;
	int size = map->dimension;
	for (i = 0; i < size; i++) {
		for (y = 0; y < size; y++) {
			matrix[i][y] = calc_dis(map->cities[i].x, map->cities[i].y,
					map->cities[y].x, map->cities[y].y);
		}
	}
	//return true;
}
Beispiel #3
0
static void calculate_neighbours(struct list *all_list, u_int neighbours,
		u_int repel) {
	struct list_elem *curr_elem = all_list->head;
	double *shortest = (double*) malloc(sizeof(double) * neighbours);
	double *fairest = (double*) malloc(sizeof(double) * repel);
	double dis;
	struct list_elem *comp_elem;
	register int i;

	do {

		comp_elem = curr_elem->right;

		for (i = 0; i < neighbours; i++) {
			shortest[i] = HUGE_VAL;

		}
		for (i = 0; i < repel; i++) {

			fairest[i] = 0.0;
		}

		do {
			dis = calc_dis(curr_elem->data->id->x, curr_elem->data->id->y,
					comp_elem->data->id->x, comp_elem->data->id->y);

			if (dis < shortest[neighbours - 1]) {
				shortest[neighbours - 1] = dis;
				curr_elem->data->neighbours[neighbours - 1] = comp_elem->data;
				sort_assending(shortest, curr_elem->data->neighbours, neighbours);

			}

			if (dis > fairest[repel - 1]) {
				fairest[repel - 1] = dis;
				curr_elem->data->remote[repel - 1] = comp_elem->data;
				sort_desending(fairest, curr_elem->data->remote, repel);
			}

			comp_elem = comp_elem->right;
		} while (comp_elem != curr_elem);
		curr_elem = curr_elem->right;

	} while (curr_elem != all_list->head);

	free(shortest);
	free(fairest);
}