PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ ptarray_segmentize_sphere_edge_recursive()

static int ptarray_segmentize_sphere_edge_recursive ( const POINT3D p1,
const POINT3D p2,
const POINT4D v1,
const POINT4D v2,
double  d,
double  max_seg_length,
POINTARRAY pa 
)
static

Definition at line 1546 of file lwgeodetic.c.

References cart2geog(), GEOGRAPHIC_POINT::lat, GEOGRAPHIC_POINT::lon, LW_FALSE, LW_SUCCESS, POINT4D::m, normalize(), ptarray_append_point(), rad2deg, POINT3D::x, POINT4D::x, POINT3D::y, POINT4D::y, POINT3D::z, and POINT4D::z.

Referenced by ptarray_segmentize_sphere().

1551 {
1552  GEOGRAPHIC_POINT g;
1553  /* Reached the terminal leaf in recursion. Add */
1554  /* the left-most point to the pointarray here */
1555  /* We recurse down the left side first, so outputs should */
1556  /* end up added to the array in order this way */
1557  if (d <= max_seg_length)
1558  {
1559  POINT4D p;
1560  cart2geog(p1, &g);
1561  p.x = v1->x;
1562  p.y = v1->y;
1563  p.z = v1->z;
1564  p.m = v1->m;
1565  return ptarray_append_point(pa, &p, LW_FALSE);
1566  }
1567  /* Find the mid-point and recurse on the left and then the right */
1568  else
1569  {
1570  /* Calculate mid-point */
1571  POINT3D mid;
1572  mid.x = (p1->x + p2->x) / 2.0;
1573  mid.y = (p1->y + p2->y) / 2.0;
1574  mid.z = (p1->z + p2->z) / 2.0;
1575  normalize(&mid);
1576 
1577  /* Calculate z/m mid-values */
1578  POINT4D midv;
1579  cart2geog(&mid, &g);
1580  midv.x = rad2deg(g.lon);
1581  midv.y = rad2deg(g.lat);
1582  midv.z = (v1->z + v2->z) / 2.0;
1583  midv.m = (v1->m + v2->m) / 2.0;
1584  /* Recurse on the left first */
1585  ptarray_segmentize_sphere_edge_recursive(p1, &mid, v1, &midv, d/2.0, max_seg_length, pa);
1586  ptarray_segmentize_sphere_edge_recursive(&mid, p2, &midv, v2, d/2.0, max_seg_length, pa);
1587  return LW_SUCCESS;
1588  }
1589 }
double x
Definition: liblwgeom.h:354
double m
Definition: liblwgeom.h:354
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:584
double y
Definition: liblwgeom.h:342
#define LW_SUCCESS
Definition: liblwgeom.h:79
void cart2geog(const POINT3D *p, GEOGRAPHIC_POINT *g)
Convert cartesian coordinates on unit sphere to spherical coordinates.
Definition: lwgeodetic.c:383
double x
Definition: liblwgeom.h:342
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:47
double z
Definition: liblwgeom.h:342
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE, then a duplicate point will not be added.
Definition: ptarray.c:156
#define LW_FALSE
Definition: liblwgeom.h:76
#define rad2deg(r)
Definition: lwgeodetic.h:75
double z
Definition: liblwgeom.h:354
double y
Definition: liblwgeom.h:354
static int ptarray_segmentize_sphere_edge_recursive(const POINT3D *p1, const POINT3D *p2, const POINT4D *v1, const POINT4D *v2, double d, double max_seg_length, POINTARRAY *pa)
Definition: lwgeodetic.c:1546
Here is the call graph for this function:
Here is the caller graph for this function: