Trisurf Monte Carlo simulator
Samo Penic
2012-06-14 c9d07c3cae70179c3045b92b7dc04f0d2ebcfb89
src/triangle.c
@@ -194,12 +194,12 @@
  */
ts_bool triangle_normal_vector(ts_triangle *tria){
   ts_double x21,x31,y21,y31,z21,z31,xden;
   x21=tria->vertex[1]->data->x - tria->vertex[0]->data->x;
   x31=tria->vertex[2]->data->x - tria->vertex[0]->data->x;
   y21=tria->vertex[1]->data->y - tria->vertex[0]->data->y;
   y31=tria->vertex[2]->data->y - tria->vertex[0]->data->y;
   z21=tria->vertex[1]->data->z - tria->vertex[0]->data->z;
   z31=tria->vertex[2]->data->z - tria->vertex[0]->data->z;
   x21=tria->vertex[1]->x - tria->vertex[0]->x;
   x31=tria->vertex[2]->x - tria->vertex[0]->x;
   y21=tria->vertex[1]->y - tria->vertex[0]->y;
   y31=tria->vertex[2]->y - tria->vertex[0]->y;
   z21=tria->vertex[1]->z - tria->vertex[0]->z;
   z31=tria->vertex[2]->z - tria->vertex[0]->z;
   tria->xnorm=y21*z31 - z21*y31;
   tria->ynorm=z21*x31 - x21*z31;
@@ -219,6 +219,18 @@
   tria->xnorm=tria->xnorm/xden;
   tria->ynorm=tria->ynorm/xden;
   tria->znorm=tria->znorm/xden;   
/*  Here it is an excellent point to recalculate volume of the triangle and
 *  store it into datastructure. Volume is required at least by constant volume
 *  calculation of vertex move and bondflip and spherical harmonics. */
    tria->volume=(tria->vertex[0]->x+ tria->vertex[1]->x + tria->vertex[2]->x) * tria->xnorm +
       (tria->vertex[0]->y+ tria->vertex[1]->y + tria->vertex[2]->y) * tria->ynorm +
    (tria->vertex[0]->z+ tria->vertex[1]->z + tria->vertex[2]->z) * tria->znorm;
    tria->volume=-xden*tria->volume/18.0;
/*  Also, area can be calculated in each triangle */
    tria->area=xden/2;
   return TS_SUCCESS;
}