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

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

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

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