00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
#include <volume_io/internal_volume_io.h>
00016
#include <bicpl/geom.h>
00017
00018
#ifndef lint
00019
static char rcsid[] =
"$Header: /software/source//libraries/bicpl/Geometry/surface_area.c,v 1.7 2000/02/06 15:30:19 stever Exp $";
00020
#endif
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 public Real
get_polygon_2d_area(
00037
int n_points,
00038 Point points[] )
00039 {
00040
int i, next_i;
00041 Real area;
00042
00043 area = 0.0;
00044
00045 for_less( i, 0, n_points )
00046 {
00047 next_i = (i + 1) % n_points;
00048 area += (Real) Point_x(points[i]) * (Real) Point_y(points[next_i])-
00049 (Real) Point_x(points[next_i]) * (Real) Point_y(points[i]);
00050 }
00051
00052
return( FABS( area / 2.0 ) );
00053 }
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 public Real
get_polygon_surface_area(
00072
int n_points,
00073 Point points[] )
00074 {
00075
int i;
00076 Vector prev,
this, cross_prod, sum;
00077 Real surface_area;
00078
00079 fill_Vector( sum, 0.0, 0.0, 0.0 );
00080 SUB_VECTORS(
this, points[1], points[0] );
00081
00082 for_less( i, 2, n_points )
00083 {
00084 prev =
this;
00085 SUB_VECTORS(
this, points[i], points[0] );
00086 CROSS_VECTORS( cross_prod, prev,
this );
00087 ADD_VECTORS( sum, sum, cross_prod );
00088 }
00089
00090 surface_area = MAGNITUDE( sum ) / 2.0;
00091
00092
return( surface_area );
00093 }
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 public Real
get_polygons_surface_area(
00109
polygons_struct *polygons )
00110 {
00111
int poly, size;
00112 Point points[
MAX_POINTS_PER_POLYGON];
00113 Real surface_area;
00114
00115 surface_area = 0.0;
00116
00117 for_less( poly, 0, polygons->
n_items )
00118 {
00119 size =
get_polygon_points( polygons, poly, points );
00120 surface_area +=
get_polygon_surface_area( size, points );
00121 }
00122
00123
return( surface_area );
00124 }