PostGIS  2.5.0dev-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 2422 of file measures.c.

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

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

2423 {
2424  if ( A->x == B->x )
2425  {
2426  if ( A->y < B->y ) *d=0.0;
2427  else if ( A->y > B->y ) *d=M_PI;
2428  else return 0;
2429  return 1;
2430  }
2431 
2432  if ( A->y == B->y )
2433  {
2434  if ( A->x < B->x ) *d=M_PI/2;
2435  else if ( A->x > B->x ) *d=M_PI+(M_PI/2);
2436  else return 0;
2437  return 1;
2438  }
2439 
2440  if ( A->x < B->x )
2441  {
2442  if ( A->y < B->y )
2443  {
2444  *d=atan(fabs(A->x - B->x) / fabs(A->y - B->y) );
2445  }
2446  else /* ( A->y > B->y ) - equality case handled above */
2447  {
2448  *d=atan(fabs(A->y - B->y) / fabs(A->x - B->x) )
2449  + (M_PI/2);
2450  }
2451  }
2452 
2453  else /* ( A->x > B->x ) - equality case handled above */
2454  {
2455  if ( A->y > B->y )
2456  {
2457  *d=atan(fabs(A->x - B->x) / fabs(A->y - B->y) )
2458  + M_PI;
2459  }
2460  else /* ( A->y < B->y ) - equality case handled above */
2461  {
2462  *d=atan(fabs(A->y - B->y) / fabs(A->x - B->x) )
2463  + (M_PI+(M_PI/2));
2464  }
2465  }
2466 
2467  return 1;
2468 }
double x
Definition: liblwgeom.h:327
double y
Definition: liblwgeom.h:327

Here is the caller graph for this function: