PostGIS  2.1.10dev-r@@SVN_REVISION@@
double gbox_angular_width ( const GBOX gbox)

Returns the angular width (longitudinal span) of the box in radians.

Definition at line 192 of file lwgeodetic.c.

References MAXFLOAT, pixval::x, POINT3D::x, GBOX::xmin, pixval::y, POINT3D::y, GBOX::ymin, and POINT3D::z.

Referenced by geography_bestsrid(), and test_gbox_utils().

193 {
194  double d[6];
195  int i, j;
196  POINT3D pt[3];
197  double maxangle;
198  double magnitude;
199 
200  /* Take a copy of the box corners so we can treat them as a list */
201  /* Elements are xmin, xmax, ymin, ymax, zmin, zmax */
202  memcpy(d, &(gbox->xmin), 6*sizeof(double));
203 
204  /* Start with the bottom corner */
205  pt[0].x = gbox->xmin;
206  pt[0].y = gbox->ymin;
207  magnitude = sqrt(pt[0].x*pt[0].x + pt[0].y*pt[0].y);
208  pt[0].x /= magnitude;
209  pt[0].y /= magnitude;
210 
211  /* Generate all 8 corner vectors of the box */
212  /* Find the vector furthest from our seed vector */
213  for ( j = 0; j < 2; j++ )
214  {
215  maxangle = -1 * MAXFLOAT;
216  for ( i = 0; i < 4; i++ )
217  {
218  double angle, dotprod;
219  POINT3D pt_n;
220 
221  pt_n.x = d[i / 2];
222  pt_n.y = d[2 + (i % 2)];
223  magnitude = sqrt(pt_n.x*pt_n.x + pt_n.y*pt_n.y);
224  pt_n.x /= magnitude;
225  pt_n.y /= magnitude;
226  pt_n.z = 0.0;
227 
228  dotprod = pt_n.x*pt[j].x + pt_n.y*pt[j].y;
229  angle = acos(dotprod > 1.0 ? 1.0 : dotprod);
230  if ( angle > maxangle )
231  {
232  pt[j+1] = pt_n;
233  maxangle = angle;
234  }
235  }
236  }
237 
238  /* Return the distance between the two furthest vectors */
239  return maxangle;
240 }
double y
Definition: liblwgeom.h:296
double x
Definition: liblwgeom.h:296
double z
Definition: liblwgeom.h:296
double ymin
Definition: liblwgeom.h:250
double xmin
Definition: liblwgeom.h:248
tuple x
Definition: pixval.py:53
#define MAXFLOAT
Largest float value.
tuple y
Definition: pixval.py:54

Here is the caller graph for this function: