PostGIS  2.5.2dev-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 2416 of file measures.c.

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

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