PostGIS  2.5.0dev-r@@SVN_REVISION@@
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 1542 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().

1547 {
1548  GEOGRAPHIC_POINT g;
1549  /* Reached the terminal leaf in recursion. Add */
1550  /* the left-most point to the pointarray here */
1551  /* We recurse down the left side first, so outputs should */
1552  /* end up added to the array in order this way */
1553  if (d <= max_seg_length)
1554  {
1555  POINT4D p;
1556  cart2geog(p1, &g);
1557  p.x = v1->x;
1558  p.y = v1->y;
1559  p.z = v1->z;
1560  p.m = v1->m;
1561  return ptarray_append_point(pa, &p, LW_FALSE);
1562  }
1563  /* Find the mid-point and recurse on the left and then the right */
1564  else
1565  {
1566  /* Calculate mid-point */
1567  POINT3D mid;
1568  mid.x = (p1->x + p2->x) / 2.0;
1569  mid.y = (p1->y + p2->y) / 2.0;
1570  mid.z = (p1->z + p2->z) / 2.0;
1571  normalize(&mid);
1572 
1573  /* Calculate z/m mid-values */
1574  POINT4D midv;
1575  cart2geog(&mid, &g);
1576  midv.x = rad2deg(g.lon);
1577  midv.y = rad2deg(g.lat);
1578  midv.z = (v1->z + v2->z) / 2.0;
1579  midv.m = (v1->m + v2->m) / 2.0;
1580  /* Recurse on the left first */
1581  ptarray_segmentize_sphere_edge_recursive(p1, &mid, v1, &midv, d/2.0, max_seg_length, pa);
1582  ptarray_segmentize_sphere_edge_recursive(&mid, p2, &midv, v2, d/2.0, max_seg_length, pa);
1583  return LW_SUCCESS;
1584  }
1585 }
double x
Definition: liblwgeom.h:351
double m
Definition: liblwgeom.h:351
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:580
double y
Definition: liblwgeom.h:339
#define LW_SUCCESS
Definition: liblwgeom.h:79
void cart2geog(const POINT3D *p, GEOGRAPHIC_POINT *g)
Convert cartesion coordinates on unit sphere to spherical coordinates.
Definition: lwgeodetic.c:379
double x
Definition: liblwgeom.h:339
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:47
double z
Definition: liblwgeom.h:339
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:351
double y
Definition: liblwgeom.h:351
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:1542

Here is the call graph for this function:

Here is the caller graph for this function: