PostGIS  2.1.10dev-r@@SVN_REVISION@@
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 542 of file measures3d.c.

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().

543 {
544  POINT3DZ c;
545  double r;
546  /*if start==end, then use pt distance */
547  if ( ( A->x == B->x) && (A->y == B->y) && (A->z == B->z) )
548  {
549  return lw_dist3d_pt_pt(p,A,dl);
550  }
551 
552 
553  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) )/( (B->x-A->x)*(B->x-A->x) +(B->y-A->y)*(B->y-A->y)+(B->z-A->z)*(B->z-A->z) );
554 
555  /*This is for finding the 3Dmaxdistance.
556  the maxdistance have to be between two vertexes,
557  compared to mindistance which can be between
558  tvo vertexes vertex.*/
559  if (dl->mode == DIST_MAX)
560  {
561  if (r>=0.5)
562  {
563  return lw_dist3d_pt_pt(p,A,dl);
564  }
565  if (r<0.5)
566  {
567  return lw_dist3d_pt_pt(p,B,dl);
568  }
569  }
570 
571  if (r<0) /*If the first vertex A is closest to the point p*/
572  {
573  return lw_dist3d_pt_pt(p,A,dl);
574  }
575  if (r>1) /*If the second vertex B is closest to the point p*/
576  {
577  return lw_dist3d_pt_pt(p,B,dl);
578  }
579 
580  /*else if the point p is closer to some point between a and b
581  then we find that point and send it to lw_dist3d_pt_pt*/
582  c.x=A->x + r * (B->x-A->x);
583  c.y=A->y + r * (B->y-A->y);
584  c.z=A->z + r * (B->z-A->z);
585 
586  return lw_dist3d_pt_pt(p,&c,dl);
587 }
double z
Definition: liblwgeom.h:290
double y
Definition: liblwgeom.h:290
double x
Definition: liblwgeom.h:290
char * r
Definition: cu_in_wkt.c:25
#define DIST_MAX
int lw_dist3d_pt_pt(POINT3DZ *thep1, POINT3DZ *thep2, DISTPTS3D *dl)
Compares incomming points and stores the points closest to each other or most far away from each othe...
Definition: measures3d.c:598
int mode
Definition: measures3d.h:29

Here is the call graph for this function:

Here is the caller graph for this function: