PostGIS  2.2.7dev-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 2411 of file measures.c.

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

Referenced by _lwt_AddEdge(), _lwt_FindAdjacentEdges(), _lwt_InitEdgeEndByLine(), and LWGEOM_azimuth().

2412 {
2413  if ( A->x == B->x )
2414  {
2415  if ( A->y < B->y ) *d=0.0;
2416  else if ( A->y > B->y ) *d=M_PI;
2417  else return 0;
2418  return 1;
2419  }
2420 
2421  if ( A->y == B->y )
2422  {
2423  if ( A->x < B->x ) *d=M_PI/2;
2424  else if ( A->x > B->x ) *d=M_PI+(M_PI/2);
2425  else return 0;
2426  return 1;
2427  }
2428 
2429  if ( A->x < B->x )
2430  {
2431  if ( A->y < B->y )
2432  {
2433  *d=atan(fabs(A->x - B->x) / fabs(A->y - B->y) );
2434  }
2435  else /* ( A->y > B->y ) - equality case handled above */
2436  {
2437  *d=atan(fabs(A->y - B->y) / fabs(A->x - B->x) )
2438  + (M_PI/2);
2439  }
2440  }
2441 
2442  else /* ( A->x > B->x ) - equality case handled above */
2443  {
2444  if ( A->y > B->y )
2445  {
2446  *d=atan(fabs(A->x - B->x) / fabs(A->y - B->y) )
2447  + M_PI;
2448  }
2449  else /* ( A->y < B->y ) - equality case handled above */
2450  {
2451  *d=atan(fabs(A->y - B->y) / fabs(A->x - B->x) )
2452  + (M_PI+(M_PI/2));
2453  }
2454  }
2455 
2456  return 1;
2457 }
double x
Definition: liblwgeom.h:312
double y
Definition: liblwgeom.h:312

Here is the caller graph for this function: