PostGIS  2.1.10dev-r@@SVN_REVISION@@
 double distance2d_pt_seg ( const POINT2D * p, const POINT2D * A, const POINT2D * B )

The old function nessecary for ptarray_segmentize2d in ptarray.c.

Definition at line 2148 of file measures.c.

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

Referenced by ptarray_locate_point().

2149 {
2150  double r,s;
2151
2152  /*if start==end, then use pt distance */
2153  if ( ( A->x == B->x) && (A->y == B->y) )
2154  return distance2d_pt_pt(p,A);
2155
2156  /*
2157  * otherwise, we use comp.graphics.algorithms
2158  * Frequently Asked Questions method
2159  *
2160  * (1) AC dot AB
2161  * r = ---------
2162  * ||AB||^2
2163  * r has the following meaning:
2164  * r=0 P = A
2165  * r=1 P = B
2166  * r<0 P is on the backward extension of AB
2167  * r>1 P is on the forward extension of AB
2168  * 0<r<1 P is interior to AB
2169  */
2170
2171  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) );
2172
2173  if (r<0) return distance2d_pt_pt(p,A);
2174  if (r>1) return distance2d_pt_pt(p,B);
2175
2176
2177  /*
2178  * (2)
2179  * (Ay-Cy)(Bx-Ax)-(Ax-Cx)(By-Ay)
2180  * s = -----------------------------
2181  * L^2
2182  *
2183  * Then the distance from C to P = |s|*L.
2184  *
2185  */
2186
2187  s = ( (A->y-p->y)*(B->x-A->x)- (A->x-p->x)*(B->y-A->y) ) /
2188  ( (B->x-A->x)*(B->x-A->x) +(B->y-A->y)*(B->y-A->y) );
2189
2190  return FP_ABS(s) * sqrt(
2191  (B->x-A->x)*(B->x-A->x) + (B->y-A->y)*(B->y-A->y)
2192  );
2193 }
char * r
Definition: cu_in_wkt.c:25
double x
Definition: liblwgeom.h:284
double y
Definition: liblwgeom.h:284
char * s
Definition: cu_in_wkt.c:24
double distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2)
The old function nessecary for ptarray_segmentize2d in ptarray.c.
Definition: measures.c:2123
#define FP_ABS(a)

Here is the call graph for this function:

Here is the caller graph for this function: