PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ lw_dist3d_pt_seg()

int lw_dist3d_pt_seg ( const POINT3DZ p,
const POINT3DZ A,
const 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 1026 of file measures3d.c.

1027{
1028 POINT3DZ c;
1029 double r;
1030 /*if start==end, then use pt distance */
1031 if ((A->x == B->x) && (A->y == B->y) && (A->z == B->z))
1032 {
1033 return lw_dist3d_pt_pt(p, A, dl);
1034 }
1035
1036 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)) /
1037 ((B->x - A->x) * (B->x - A->x) + (B->y - A->y) * (B->y - A->y) + (B->z - A->z) * (B->z - A->z));
1038
1039 /*This is for finding the 3Dmaxdistance.
1040 the maxdistance have to be between two vertices,
1041 compared to mindistance which can be between
1042 two vertices vertex.*/
1043 if (dl->mode == DIST_MAX)
1044 {
1045 if (r >= 0.5)
1046 return lw_dist3d_pt_pt(p, A, dl);
1047 if (r < 0.5)
1048 return lw_dist3d_pt_pt(p, B, dl);
1049 }
1050
1051 if (r <= 0) /*If the first vertex A is closest to the point p*/
1052 return lw_dist3d_pt_pt(p, A, dl);
1053 if (r >= 1) /*If the second vertex B is closest to the point p*/
1054 return lw_dist3d_pt_pt(p, B, dl);
1055
1056 /*else if the point p is closer to some point between a and b
1057 then we find that point and send it to lw_dist3d_pt_pt*/
1058 c.x = A->x + r * (B->x - A->x);
1059 c.y = A->y + r * (B->y - A->y);
1060 c.z = A->z + r * (B->z - A->z);
1061
1062 return lw_dist3d_pt_pt(p, &c, dl);
1063}
char * r
Definition cu_in_wkt.c:24
int lw_dist3d_pt_pt(const POINT3DZ *thep1, const POINT3DZ *thep2, DISTPTS3D *dl)
Compares incoming points and stores the points closest to each other or most far away from each other...
#define DIST_MAX
Definition measures.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: