PostGIS  3.4.0dev-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 1639 of file lwgeodetic.c.

1644 {
1645  GEOGRAPHIC_POINT g;
1646  /* Reached the terminal leaf in recursion. Add */
1647  /* the left-most point to the pointarray here */
1648  /* We recurse down the left side first, so outputs should */
1649  /* end up added to the array in order this way */
1650  if (d <= max_seg_length)
1651  {
1652  POINT4D p;
1653  cart2geog(p1, &g);
1654  p.x = v1->x;
1655  p.y = v1->y;
1656  p.z = v1->z;
1657  p.m = v1->m;
1658  return ptarray_append_point(pa, &p, LW_FALSE);
1659  }
1660  /* Find the mid-point and recurse on the left and then the right */
1661  else
1662  {
1663  /* Calculate mid-point */
1664  POINT3D mid;
1665  mid.x = (p1->x + p2->x) / 2.0;
1666  mid.y = (p1->y + p2->y) / 2.0;
1667  mid.z = (p1->z + p2->z) / 2.0;
1668  normalize(&mid);
1669 
1670  /* Calculate z/m mid-values */
1671  POINT4D midv;
1672  cart2geog(&mid, &g);
1673  midv.x = rad2deg(g.lon);
1674  midv.y = rad2deg(g.lat);
1675  midv.z = (v1->z + v2->z) / 2.0;
1676  midv.m = (v1->m + v2->m) / 2.0;
1677  /* Recurse on the left first */
1678  ptarray_segmentize_sphere_edge_recursive(p1, &mid, v1, &midv, d/2.0, max_seg_length, pa);
1679  ptarray_segmentize_sphere_edge_recursive(&mid, p2, &midv, v2, d/2.0, max_seg_length, pa);
1680  return LW_SUCCESS;
1681  }
1682 }
#define LW_FALSE
Definition: liblwgeom.h:94
#define LW_SUCCESS
Definition: liblwgeom.h:97
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,...
Definition: ptarray.c:147
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:615
void cart2geog(const POINT3D *p, GEOGRAPHIC_POINT *g)
Convert cartesian coordinates on unit sphere to spherical coordinates.
Definition: lwgeodetic.c:414
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:1639
#define rad2deg(r)
Definition: lwgeodetic.h:81
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:54
double z
Definition: liblwgeom.h:402
double x
Definition: liblwgeom.h:402
double y
Definition: liblwgeom.h:402
double m
Definition: liblwgeom.h:414
double x
Definition: liblwgeom.h:414
double z
Definition: liblwgeom.h:414
double y
Definition: liblwgeom.h:414

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().

Here is the call graph for this function:
Here is the caller graph for this function: