PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ 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 191 of file lwgeodetic_tree.c.

192{
193 POINT3D p1, p2;
194 POINT3D p1p2, pc;
195 double proportion = offset/distance;
196
197 LWDEBUG(4,"calculating cartesian center");
198
199 geog2cart(c1, &p1);
200 geog2cart(c2, &p2);
201
202 /* Difference between p2 and p1 */
203 p1p2.x = p2.x - p1.x;
204 p1p2.y = p2.y - p1.y;
205 p1p2.z = p2.z - p1.z;
206
207 /* Scale difference to proportion */
208 p1p2.x *= proportion;
209 p1p2.y *= proportion;
210 p1p2.z *= proportion;
211
212 /* Add difference to p1 to get approximate center point */
213 pc.x = p1.x + p1p2.x;
214 pc.y = p1.y + p1p2.y;
215 pc.z = p1.z + p1p2.z;
216 normalize(&pc);
217
218 /* Convert center point to geographics */
219 cart2geog(&pc, center);
220
221 return LW_SUCCESS;
222}
#define LW_SUCCESS
Definition liblwgeom.h:97
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
#define LWDEBUG(level, msg)
Definition lwgeom_log.h:101
static double distance(double x1, double y1, double x2, double y2)
Definition lwtree.c:1032
double z
Definition liblwgeom.h:402
double x
Definition liblwgeom.h:402
double y
Definition liblwgeom.h:402

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: