PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ lw_dist3d_pt_seg()

int lw_dist3d_pt_seg ( POINT3DZ p,
POINT3DZ A,
POINT3DZ B,
DISTPTS3D dl 
)

If searching for min distance, this one finds the closest point on segment A-B from p.

if searching for max distance it just sends p-A and p-B to pt-pt calculation

Definition at line 989 of file measures3d.c.

990 {
991  POINT3DZ c;
992  double r;
993  /*if start==end, then use pt distance */
994  if ((A->x == B->x) && (A->y == B->y) && (A->z == B->z))
995  {
996  return lw_dist3d_pt_pt(p, A, dl);
997  }
998 
999  r = ((p->x - A->x) * (B->x - A->x) + (p->y - A->y) * (B->y - A->y) + (p->z - A->z) * (B->z - A->z)) /
1000  ((B->x - A->x) * (B->x - A->x) + (B->y - A->y) * (B->y - A->y) + (B->z - A->z) * (B->z - A->z));
1001 
1002  /*This is for finding the 3Dmaxdistance.
1003  the maxdistance have to be between two vertexes,
1004  compared to mindistance which can be between
1005  two vertexes vertex.*/
1006  if (dl->mode == DIST_MAX)
1007  {
1008  if (r >= 0.5)
1009  return lw_dist3d_pt_pt(p, A, dl);
1010  if (r < 0.5)
1011  return lw_dist3d_pt_pt(p, B, dl);
1012  }
1013 
1014  if (r <= 0) /*If the first vertex A is closest to the point p*/
1015  return lw_dist3d_pt_pt(p, A, dl);
1016  if (r >= 1) /*If the second vertex B is closest to the point p*/
1017  return lw_dist3d_pt_pt(p, B, dl);
1018 
1019  /*else if the point p is closer to some point between a and b
1020  then we find that point and send it to lw_dist3d_pt_pt*/
1021  c.x = A->x + r * (B->x - A->x);
1022  c.y = A->y + r * (B->y - A->y);
1023  c.z = A->z + r * (B->z - A->z);
1024 
1025  return lw_dist3d_pt_pt(p, &c, dl);
1026 }
char * r
Definition: cu_in_wkt.c:24
int lw_dist3d_pt_pt(POINT3DZ *thep1, POINT3DZ *thep2, DISTPTS3D *dl)
Compares incoming points and stores the points closest to each other or most far away from each other...
Definition: measures3d.c:1045
#define DIST_MAX
Definition: measures.h:43
int mode
Definition: measures3d.h:43
double z
Definition: liblwgeom.h:396
double x
Definition: liblwgeom.h:396
double y
Definition: liblwgeom.h:396

References DIST_MAX, lw_dist3d_pt_pt(), DISTPTS3D::mode, r, POINT3DZ::x, POINT3DZ::y, and POINT3DZ::z.

Referenced by lw_dist3d_pt_ptarray(), and lw_dist3d_seg_seg().

Here is the call graph for this function:
Here is the caller graph for this function: