PostGIS  2.3.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 2425 of file measures.c.

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

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

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

Here is the caller graph for this function: