Statistiques
| Révision :

root / bin / compute_barycenters.cpp @ 1

Historique | Voir | Annoter | Télécharger (821 octet)

1
#include "compute_barycenters.h"
2
#include <stdio.h>
3
#include <stdlib.h>
4
#include <math.h>
5

    
6
/* knowing the vertices in each cell, computation of the center of each cell */
7

    
8
void compute_barycenters(double *vertices, int vertices_number, int *cells_vertices,
9
                     int *vertices_number_in_each_cell, int cell_number, double *barycenters){
10

    
11
int i,j,min,max; double N;
12

    
13
for (i=0;i<cell_number;i++){barycenters[2*i]=0; barycenters[2*i+1]=0;}
14

    
15
for (i=0;i<cell_number;i++){ min=vertices_number_in_each_cell[i]; max=vertices_number_in_each_cell[i+1]; N=(double)(max-min);
16
    for (j=0;j<max-min;j++){
17
        barycenters[2*i]+=vertices[2*cells_vertices[min+j]];
18
        barycenters[2*i+1]+=vertices[2*cells_vertices[min+j]+1];
19
        }
20
    barycenters[2*i]/=N;
21
    barycenters[2*i+1]/=N;
22
}
23

    
24
}