PostGIS  2.4.9dev-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 2427 of file measures.c.

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

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

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