PostGIS  3.0.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 2407 of file measures.c.

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

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

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