PostGIS  2.1.10dev-r@@SVN_REVISION@@
int azimuth_pt_pt ( const POINT2D A,
const POINT2D B,
double *  d 
)

Compute the azimuth of segment AB in radians.

Return 0 on exception (same point), 1 otherwise.

Definition at line 2233 of file measures.c.

References POINT2D::x, and POINT2D::y.

Referenced by LWGEOM_azimuth().

2234 {
2235  if ( A->x == B->x )
2236  {
2237  if ( A->y < B->y ) *d=0.0;
2238  else if ( A->y > B->y ) *d=M_PI;
2239  else return 0;
2240  return 1;
2241  }
2242 
2243  if ( A->y == B->y )
2244  {
2245  if ( A->x < B->x ) *d=M_PI/2;
2246  else if ( A->x > B->x ) *d=M_PI+(M_PI/2);
2247  else return 0;
2248  return 1;
2249  }
2250 
2251  if ( A->x < B->x )
2252  {
2253  if ( A->y < B->y )
2254  {
2255  *d=atan(fabs(A->x - B->x) / fabs(A->y - B->y) );
2256  }
2257  else /* ( A->y > B->y ) - equality case handled above */
2258  {
2259  *d=atan(fabs(A->y - B->y) / fabs(A->x - B->x) )
2260  + (M_PI/2);
2261  }
2262  }
2263 
2264  else /* ( A->x > B->x ) - equality case handled above */
2265  {
2266  if ( A->y > B->y )
2267  {
2268  *d=atan(fabs(A->x - B->x) / fabs(A->y - B->y) )
2269  + M_PI;
2270  }
2271  else /* ( A->y < B->y ) - equality case handled above */
2272  {
2273  *d=atan(fabs(A->y - B->y) / fabs(A->x - B->x) )
2274  + (M_PI+(M_PI/2));
2275  }
2276  }
2277 
2278  return 1;
2279 }
double x
Definition: liblwgeom.h:284
double y
Definition: liblwgeom.h:284

Here is the caller graph for this function: