PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ distance2d_sqr_pt_seg()

double distance2d_sqr_pt_seg ( const POINT2D p,
const POINT2D A,
const POINT2D B 
)

Definition at line 2381 of file measures.c.

2382 {
2383  double r,s;
2384 
2385  if ( ( A->x == B->x) && (A->y == B->y) )
2386  return distance2d_sqr_pt_pt(p,A);
2387 
2388  r = ( (p->x-A->x) * (B->x-A->x) + (p->y-A->y) * (B->y-A->y) )/( (B->x-A->x)*(B->x-A->x) +(B->y-A->y)*(B->y-A->y) );
2389 
2390  if (r<0) return distance2d_sqr_pt_pt(p,A);
2391  if (r>1) return distance2d_sqr_pt_pt(p,B);
2392 
2393 
2394  /*
2395  * (2)
2396  * (Ay-Cy)(Bx-Ax)-(Ax-Cx)(By-Ay)
2397  * s = -----------------------------
2398  * L^2
2399  *
2400  * Then the distance from C to P = |s|*L.
2401  *
2402  */
2403 
2404  s = ( (A->y-p->y)*(B->x-A->x)- (A->x-p->x)*(B->y-A->y) ) /
2405  ( (B->x-A->x)*(B->x-A->x) +(B->y-A->y)*(B->y-A->y) );
2406 
2407  return s * s * ( (B->x-A->x)*(B->x-A->x) + (B->y-A->y)*(B->y-A->y) );
2408 }
char * s
Definition: cu_in_wkt.c:23
char * r
Definition: cu_in_wkt.c:24
double distance2d_sqr_pt_pt(const POINT2D *p1, const POINT2D *p2)
Definition: measures.c:2323
double y
Definition: liblwgeom.h:331
double x
Definition: liblwgeom.h:331

References distance2d_sqr_pt_pt(), r, s, POINT2D::x, and POINT2D::y.

Referenced by ptarray_dp_findsplit_in_place().

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