PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ circ_center_cartesian()

static int circ_center_cartesian ( const GEOGRAPHIC_POINT c1,
const GEOGRAPHIC_POINT c2,
double  distance,
double  offset,
GEOGRAPHIC_POINT center 
)
static

Where the circ_center_spherical() function fails, we need a fall-back.

The failures happen in short arcs, where the spherical distance between two points is practically the same as the straight-line distance, so our fallback will be to use the straight-line between the two to calculate the new projected center. For proportions far from 0.5 this will be increasingly more incorrect.

Definition at line 190 of file lwgeodetic_tree.c.

References cart2geog(), distance(), geog2cart(), LW_SUCCESS, LWDEBUG, normalize(), POINT3D::x, POINT3D::y, and POINT3D::z.

Referenced by circ_node_internal_new().

191 {
192  POINT3D p1, p2;
193  POINT3D p1p2, pc;
194  double proportion = offset/distance;
195 
196  LWDEBUG(4,"calculating cartesian center");
197 
198  geog2cart(c1, &p1);
199  geog2cart(c2, &p2);
200 
201  /* Difference between p2 and p1 */
202  p1p2.x = p2.x - p1.x;
203  p1p2.y = p2.y - p1.y;
204  p1p2.z = p2.z - p1.z;
205 
206  /* Scale difference to proportion */
207  p1p2.x *= proportion;
208  p1p2.y *= proportion;
209  p1p2.z *= proportion;
210 
211  /* Add difference to p1 to get approximate center point */
212  pc.x = p1.x + p1p2.x;
213  pc.y = p1.y + p1p2.y;
214  pc.z = p1.z + p1p2.z;
215  normalize(&pc);
216 
217  /* Convert center point to geographics */
218  cart2geog(&pc, center);
219 
220  return LW_SUCCESS;
221 }
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:611
double y
Definition: liblwgeom.h:340
#define LW_SUCCESS
Definition: liblwgeom.h:80
void cart2geog(const POINT3D *p, GEOGRAPHIC_POINT *g)
Convert cartesion coordinates on unit sphere to spherical coordinates.
Definition: lwgeodetic.c:410
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
double x
Definition: liblwgeom.h:340
double z
Definition: liblwgeom.h:340
Datum distance(PG_FUNCTION_ARGS)
void geog2cart(const GEOGRAPHIC_POINT *g, POINT3D *p)
Convert spherical coordinates to cartesion coordinates on unit sphere.
Definition: lwgeodetic.c:400
Here is the call graph for this function:
Here is the caller graph for this function: