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
#include <bicpl/trans.h>
00018
00019
#ifndef lint
00020
static char rcsid[] =
"$Header: /software/source//libraries/bicpl/Geometry/points.c,v 1.8 2000/02/06 15:30:16 stever Exp $";
00021
#endif
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 public BOOLEAN
null_Point(
00037 Point *p )
00038 {
00039
return( Point_x(*p) == 0.0f &&
00040 Point_y(*p) == 0.0f &&
00041 Point_z(*p) == 0.0f );
00042 }
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 public BOOLEAN
null_Vector(
00058 Vector *v )
00059 {
00060
return( Vector_x(*v) == 0.0f &&
00061 Vector_y(*v) == 0.0f &&
00062 Vector_z(*v) == 0.0f );
00063 }
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 public Real
distance_between_points(
00080 Point *p1,
00081 Point *p2 )
00082 {
00083 Real dx, dy, dz;
00084
00085 dx = (Real) Point_x(*p2) - (Real) Point_x(*p1);
00086 dy = (Real) Point_y(*p2) - (Real) Point_y(*p1);
00087 dz = (Real) Point_z(*p2) - (Real) Point_z(*p1);
00088
00089
return( sqrt( dx * dx + dy * dy + dz * dz ) );
00090 }
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 public BOOLEAN
points_within_distance(
00109 Point *p1,
00110 Point *p2,
00111 Real distance )
00112 {
00113 Real dx, dy, dz;
00114
00115 dx = (Real) Point_x(*p1) - (Real) Point_x(*p2);
00116 dy = (Real) Point_y(*p1) - (Real) Point_y(*p2);
00117 dz = (Real) Point_z(*p1) - (Real) Point_z(*p2);
00118
00119
return( dx * dx + dy * dy + dz * dz <= distance * distance );
00120 }
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 public void apply_point_to_min_and_max(
00142 Point *point,
00143 Point *min_point,
00144 Point *max_point )
00145 {
00146
int c;
00147
00148 for_less( c, 0, N_DIMENSIONS )
00149 {
00150
if( Point_coord(*point,c) < Point_coord(*min_point,c) )
00151 Point_coord(*min_point,c) = Point_coord(*point,c);
00152
00153
if( Point_coord(*point,c) > Point_coord(*max_point,c) )
00154 Point_coord(*max_point,c) = Point_coord(*point,c);
00155 }
00156 }
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 public void expand_min_and_max_points(
00176 Point *min_point,
00177 Point *max_point,
00178 Point *min_to_check,
00179 Point *max_to_check )
00180 {
00181
int c;
00182
00183 for_less( c, 0, N_DIMENSIONS )
00184 {
00185
if( Point_coord(*min_to_check,c) < Point_coord(*min_point,c) )
00186 Point_coord(*min_point,c) = Point_coord(*min_to_check,c);
00187
if( Point_coord(*max_to_check,c) > Point_coord(*max_point,c) )
00188 Point_coord(*max_point,c) = Point_coord(*max_to_check,c);
00189 }
00190 }
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 public void get_range_points(
00208
int n_points,
00209 Point points[],
00210 Point *min_corner,
00211 Point *max_corner )
00212 {
00213
int i;
00214
00215
if( n_points > 0 )
00216 {
00217 *min_corner = points[0];
00218 *max_corner = points[0];
00219
00220 for_less( i, 1, n_points )
00221 {
00222
apply_point_to_min_and_max( &points[i], min_corner, max_corner );
00223 }
00224 }
00225 }
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241 public void get_points_centroid(
00242
int n_points,
00243 Point points[],
00244 Point *centroid )
00245 {
00246
int i;
00247 Real x,
y, z;
00248
00249 x = 0.0;
00250
y = 0.0;
00251 z = 0.0;
00252
00253 for_less( i, 0, n_points )
00254 {
00255 x += (Real) Point_x(points[i]);
00256
y += (Real) Point_y(points[i]);
00257 z += (Real) Point_z(points[i]);
00258 }
00259
00260 fill_Point( *centroid, x / (Real) n_points,
00261
y / (Real) n_points,
00262 z / (Real) n_points );
00263 }
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279 public void reverse_vectors(
00280
int n_vectors,
00281 Vector vectors[] )
00282 {
00283
int i;
00284
00285 for_less( i, 0, n_vectors )
00286 SCALE_VECTOR( vectors[i], vectors[i], -1.0 );
00287 }
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305 public Real
get_angle_between_points(
00306 Point *prev_point,
00307 Point *this_point,
00308 Point *next_point )
00309 {
00310 Real angle, c;
00311 Vector v1, v2;
00312
00313 SUB_POINTS( v1, *prev_point, *this_point );
00314 SUB_POINTS( v2, *next_point, *this_point );
00315
00316 NORMALIZE_VECTOR( v1, v1 );
00317 NORMALIZE_VECTOR( v2, v2 );
00318
00319 c = DOT_VECTORS( v1, v2 );
00320
00321
if( c >= 1.0 )
00322 angle = 0.0;
00323
else if( c <= -1.0 )
00324 angle = PI;
00325
else
00326 angle = acos( c );
00327
00328
return( angle );
00329 }