PostGIS  3.0.6dev-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 992 of file measures3d.c.

993 {
994  POINT3DZ c;
995  double r;
996  /*if start==end, then use pt distance */
997  if ((A->x == B->x) && (A->y == B->y) && (A->z == B->z))
998  {
999  return lw_dist3d_pt_pt(p, A, dl);
1000  }
1001 
1002  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)) /
1003  ((B->x - A->x) * (B->x - A->x) + (B->y - A->y) * (B->y - A->y) + (B->z - A->z) * (B->z - A->z));
1004 
1005  /*This is for finding the 3Dmaxdistance.
1006  the maxdistance have to be between two vertexes,
1007  compared to mindistance which can be between
1008  two vertexes vertex.*/
1009  if (dl->mode == DIST_MAX)
1010  {
1011  if (r >= 0.5)
1012  return lw_dist3d_pt_pt(p, A, dl);
1013  if (r < 0.5)
1014  return lw_dist3d_pt_pt(p, B, dl);
1015  }
1016 
1017  if (r <= 0) /*If the first vertex A is closest to the point p*/
1018  return lw_dist3d_pt_pt(p, A, dl);
1019  if (r >= 1) /*If the second vertex B is closest to the point p*/
1020  return lw_dist3d_pt_pt(p, B, dl);
1021 
1022  /*else if the point p is closer to some point between a and b
1023  then we find that point and send it to lw_dist3d_pt_pt*/
1024  c.x = A->x + r * (B->x - A->x);
1025  c.y = A->y + r * (B->y - A->y);
1026  c.z = A->z + r * (B->z - A->z);
1027 
1028  return lw_dist3d_pt_pt(p, &c, dl);
1029 }
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:1048
#define DIST_MAX
Definition: measures.h:43
int mode
Definition: measures3d.h:43
double z
Definition: liblwgeom.h:382
double x
Definition: liblwgeom.h:382
double y
Definition: liblwgeom.h:382

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: