GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
vector/vedit/distance.c
Go to the documentation of this file.
1 
14 #include <grass/vedit.h>
15 
27 double Vedit_get_min_distance(struct line_pnts *Points1,
28  struct line_pnts *Points2, int with_z,
29  int *mindistidx)
30 {
31  unsigned int i;
32  double distances[4];
33 
34  /*
35  distances[0] = first-first
36  distances[1] = first-last
37  distances[2] = last-first
38  distances[3] = last-last
39  */
40 
41  distances[0] =
42  Vect_points_distance(Points1->x[0], Points1->y[0], Points1->z[0],
43  Points2->x[0], Points2->y[0], Points2->z[0],
44  with_z);
45 
46  distances[1] =
47  Vect_points_distance(Points1->x[0], Points1->y[0], Points1->z[0],
48  Points2->x[Points2->n_points - 1],
49  Points2->y[Points2->n_points - 1],
50  Points2->z[Points2->n_points - 1], with_z);
51 
52  distances[2] = Vect_points_distance(Points1->x[Points1->n_points - 1],
53  Points1->y[Points1->n_points - 1],
54  Points1->z[Points1->n_points - 1],
55  Points2->x[0], Points2->y[0],
56  Points2->z[0], with_z);
57 
58  distances[3] = Vect_points_distance(Points1->x[Points1->n_points - 1],
59  Points1->y[Points1->n_points - 1],
60  Points1->z[Points1->n_points - 1],
61  Points2->x[Points2->n_points - 1],
62  Points2->y[Points2->n_points - 1],
63  Points2->z[Points2->n_points - 1],
64  with_z);
65 
66  /* find the minimal distance between first or last point of both lines */
67  *mindistidx = 0;
68  for (i = 0; i < sizeof(distances) / sizeof(double); i++) {
69  if (distances[i] >= 0.0 && distances[i] < distances[*mindistidx])
70  *mindistidx = i;
71  }
72 
73  G_debug(3, "Vedit_get_min_distance(): dists=%f,%f,%f,%f",
74  distances[0], distances[1], distances[2], distances[3]);
75 
76  return distances[*mindistidx];
77 }
double Vedit_get_min_distance(struct line_pnts *Points1, struct line_pnts *Points2, int with_z, int *mindistidx)
Calculate distances between two lines.
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: gis/debug.c:51
double Vect_points_distance(double x1, double y1, double z1, double x2, double y2, double z2, int with_z)
Calculate distance of 2 points.
Definition: line.c:745