PostGIS  2.5.7dev-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 192 of file lwgeodetic_tree.c.

193 {
194  POINT3D p1, p2;
195  POINT3D p1p2, pc;
196  double proportion = offset/distance;
197 
198  LWDEBUG(4,"calculating cartesian center");
199 
200  geog2cart(c1, &p1);
201  geog2cart(c2, &p2);
202 
203  /* Difference between p2 and p1 */
204  p1p2.x = p2.x - p1.x;
205  p1p2.y = p2.y - p1.y;
206  p1p2.z = p2.z - p1.z;
207 
208  /* Scale difference to proportion */
209  p1p2.x *= proportion;
210  p1p2.y *= proportion;
211  p1p2.z *= proportion;
212 
213  /* Add difference to p1 to get approximate center point */
214  pc.x = p1.x + p1p2.x;
215  pc.y = p1.y + p1p2.y;
216  pc.z = p1.z + p1p2.z;
217  normalize(&pc);
218 
219  /* Convert center point to geographics */
220  cart2geog(&pc, center);
221 
222  return LW_SUCCESS;
223 }
#define LW_SUCCESS
Definition: liblwgeom.h:80
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
void geog2cart(const GEOGRAPHIC_POINT *g, POINT3D *p)
Convert spherical coordinates to cartesian coordinates on unit sphere.
Definition: lwgeodetic.c:404
Datum distance(PG_FUNCTION_ARGS)
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
double z
Definition: liblwgeom.h:343
double x
Definition: liblwgeom.h:343
double y
Definition: liblwgeom.h:343

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

Referenced by circ_node_internal_new().

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