00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <math.h>
00021 #include <grass/Vect.h>
00022
00023
00024 #ifndef HUGE_VAL
00025 #define HUGE_VAL 9999999999999.0
00026 #endif
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 int
00037 dig_get_poly_points ( int n_lines,
00038 struct line_pnts **LPoints,
00039 int *direction,
00040 struct line_pnts *BPoints
00041 )
00042 {
00043 register int i, j, point, start, end, inc;
00044 struct line_pnts *Points;
00045 int n_points;
00046
00047 BPoints->n_points = 0;
00048
00049 if ( n_lines < 1 ) { return 0; }
00050
00051
00052 n_points = 0;
00053 for (i = 0; i < n_lines; i++) {
00054 Points = LPoints[i];
00055 n_points += Points->n_points - 1;
00056 }
00057 n_points++;
00058
00059 if (0 > dig_alloc_points (BPoints, n_points))
00060 return (-1);
00061
00062 point = 0; j = 0;
00063 for (i = 0; i < n_lines; i++) {
00064 Points = LPoints[i];
00065 if (direction[i] > 0) {
00066 start = 0;
00067 end = Points->n_points - 1;
00068 inc = 1;
00069 } else {
00070 start = Points->n_points - 1;
00071 end = 0;
00072 inc = -1;
00073 }
00074
00075 for ( j = start; j != end; j += inc) {
00076 BPoints->x[point] = Points->x[j];
00077 BPoints->y[point] = Points->y[j];
00078 }
00079 point++;
00080 }
00081
00082 BPoints->x[point] = Points->x[j];
00083 BPoints->y[point] = Points->y[j];
00084
00085 BPoints->n_points = n_points;
00086
00087 return (BPoints->n_points);
00088 }
00089
00090
00091
00092
00093
00094
00095 int
00096 dig_find_area_poly (
00097 struct line_pnts *Points,
00098 double *totalarea)
00099 {
00100 int i;
00101 double *x, *y;
00102 double tot_area, sum_area;
00103
00104
00105 *totalarea = 0.;
00106
00107 tot_area = 0.0;
00108
00109 x = Points->x;
00110 y = Points->y;
00111
00112 sum_area = 0.0;
00113 for (i = 1; i < Points->n_points; i++)
00114 {
00115 sum_area += (x[i] - x[i - 1]) * (y[i] + y[i - 1]);
00116 }
00117 tot_area += sum_area;
00118
00119 *totalarea = 0.5 * tot_area;
00120
00121 return (0);
00122 }