PostGIS  2.5.7dev-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 2417 of file measures.c.

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

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

Here is the caller graph for this function: