PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ azimuth_pt_pt()

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 2426 of file measures.c.

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

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

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