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

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

Definition at line 191 of file lwgeodetic.c.

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

Referenced by geography_bestsrid(), and test_gbox_utils().

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

Here is the caller graph for this function: