GRASS Programmer's Manual
6.4.2(2012)
|
00001 00014 #include <grass/vedit.h> 00015 00027 double Vedit_get_min_distance(struct line_pnts *Points1, 00028 struct line_pnts *Points2, int with_z, 00029 int *mindistidx) 00030 { 00031 unsigned int i; 00032 double distances[4]; 00033 00034 /* 00035 distances[0] = first-first 00036 distances[1] = first-last 00037 distances[2] = last-first 00038 distances[3] = last-last 00039 */ 00040 00041 distances[0] = 00042 Vect_points_distance(Points1->x[0], Points1->y[0], Points1->z[0], 00043 Points2->x[0], Points2->y[0], Points2->z[0], 00044 with_z); 00045 00046 distances[1] = 00047 Vect_points_distance(Points1->x[0], Points1->y[0], Points1->z[0], 00048 Points2->x[Points2->n_points - 1], 00049 Points2->y[Points2->n_points - 1], 00050 Points2->z[Points2->n_points - 1], with_z); 00051 00052 distances[2] = Vect_points_distance(Points1->x[Points1->n_points - 1], 00053 Points1->y[Points1->n_points - 1], 00054 Points1->z[Points1->n_points - 1], 00055 Points2->x[0], Points2->y[0], 00056 Points2->z[0], with_z); 00057 00058 distances[3] = Vect_points_distance(Points1->x[Points1->n_points - 1], 00059 Points1->y[Points1->n_points - 1], 00060 Points1->z[Points1->n_points - 1], 00061 Points2->x[Points2->n_points - 1], 00062 Points2->y[Points2->n_points - 1], 00063 Points2->z[Points2->n_points - 1], 00064 with_z); 00065 00066 /* find the minimal distance between first or last point of both lines */ 00067 *mindistidx = 0; 00068 for (i = 0; i < sizeof(distances) / sizeof(double); i++) { 00069 if (distances[i] >= 0.0 && distances[i] < distances[*mindistidx]) 00070 *mindistidx = i; 00071 } 00072 00073 G_debug(3, "Vedit_get_min_distance(): dists=%f,%f,%f,%f", 00074 distances[0], distances[1], distances[2], distances[3]); 00075 00076 return distances[*mindistidx]; 00077 }