PostGIS  2.2.8dev-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 2412 of file measures.c.

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

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

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