PostGIS  2.5.0beta1dev-r@@SVN_REVISION@@

◆ gbox_angular_width()

double gbox_angular_width ( const GBOX gbox)

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

Definition at line 206 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().

207 {
208  double d[6];
209  int i, j;
210  POINT3D pt[3];
211  double maxangle;
212  double magnitude;
213 
214  /* Take a copy of the box corners so we can treat them as a list */
215  /* Elements are xmin, xmax, ymin, ymax, zmin, zmax */
216  memcpy(d, &(gbox->xmin), 6*sizeof(double));
217 
218  /* Start with the bottom corner */
219  pt[0].x = gbox->xmin;
220  pt[0].y = gbox->ymin;
221  magnitude = sqrt(pt[0].x*pt[0].x + pt[0].y*pt[0].y);
222  pt[0].x /= magnitude;
223  pt[0].y /= magnitude;
224 
225  /* Generate all 8 corner vectors of the box */
226  /* Find the vector furthest from our seed vector */
227  for ( j = 0; j < 2; j++ )
228  {
229  maxangle = -1 * FLT_MAX;
230  for ( i = 0; i < 4; i++ )
231  {
232  double angle, dotprod;
233  POINT3D pt_n;
234 
235  pt_n.x = d[i / 2];
236  pt_n.y = d[2 + (i % 2)];
237  magnitude = sqrt(pt_n.x*pt_n.x + pt_n.y*pt_n.y);
238  pt_n.x /= magnitude;
239  pt_n.y /= magnitude;
240  pt_n.z = 0.0;
241 
242  dotprod = pt_n.x*pt[j].x + pt_n.y*pt[j].y;
243  angle = acos(dotprod > 1.0 ? 1.0 : dotprod);
244  if ( angle > maxangle )
245  {
246  pt[j+1] = pt_n;
247  maxangle = angle;
248  }
249  }
250  }
251 
252  /* Return the distance between the two furthest vectors */
253  return maxangle;
254 }
double y
Definition: liblwgeom.h:342
double x
Definition: liblwgeom.h:342
double z
Definition: liblwgeom.h:342
double ymin
Definition: liblwgeom.h:296
double xmin
Definition: liblwgeom.h:294
Here is the caller graph for this function: