PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lw_dist2d_pt_arc()

int lw_dist2d_pt_arc ( const POINT2D P,
const POINT2D A1,
const POINT2D A2,
const POINT2D A3,
DISTPTS dl 
)

Definition at line 1435 of file measures.c.

References DISTPTS::distance, distance2d_pt_pt(), FP_EQUALS, lw_arc_center(), lw_arc_is_pt(), lw_dist2d_arc_arc_concentric(), lw_dist2d_pt_pt(), lw_dist2d_pt_seg(), lw_pt_in_arc(), LW_TRUE, lwerror(), DISTPTS::mode, DISTPTS::p1, DISTPTS::p2, p2d_same(), POINT2D::x, and POINT2D::y.

Referenced by lw_dist2d_arc_arc(), lw_dist2d_pt_ptarrayarc(), lw_dist2d_seg_arc(), and test_lw_dist2d_pt_arc().

1436 {
1437  double radius_A, d;
1438  POINT2D C; /* center of circle defined by arc A */
1439  POINT2D X; /* point circle(A) where line from C to P crosses */
1440 
1441  if ( dl->mode < 0 )
1442  lwerror("lw_dist2d_pt_arc does not support maxdistance mode");
1443 
1444  /* What if the arc is a point? */
1445  if ( lw_arc_is_pt(A1, A2, A3) )
1446  return lw_dist2d_pt_pt(P, A1, dl);
1447 
1448  /* Calculate centers and radii of circles. */
1449  radius_A = lw_arc_center(A1, A2, A3, &C);
1450 
1451  /* This "arc" is actually a line (A2 is colinear with A1,A3) */
1452  if ( radius_A < 0.0 )
1453  return lw_dist2d_pt_seg(P, A1, A3, dl);
1454 
1455  /* Distance from point to center */
1456  d = distance2d_pt_pt(&C, P);
1457 
1458  /* P is the center of the circle */
1459  if ( FP_EQUALS(d, 0.0) )
1460  {
1461  dl->distance = radius_A;
1462  dl->p1 = *A1;
1463  dl->p2 = *P;
1464  return LW_TRUE;
1465  }
1466 
1467  /* X is the point on the circle where the line from P to C crosses */
1468  X.x = C.x + (P->x - C.x) * radius_A / d;
1469  X.y = C.y + (P->y - C.y) * radius_A / d;
1470 
1471  /* Is crossing point inside the arc? Or arc is actually circle? */
1472  if ( p2d_same(A1, A3) || lw_pt_in_arc(&X, A1, A2, A3) )
1473  {
1474  lw_dist2d_pt_pt(P, &X, dl);
1475  }
1476  else
1477  {
1478  /* Distance is the minimum of the distances to the arc end points */
1479  lw_dist2d_pt_pt(A1, P, dl);
1480  lw_dist2d_pt_pt(A3, P, dl);
1481  }
1482  return LW_TRUE;
1483 }
double lw_arc_center(const POINT2D *p1, const POINT2D *p2, const POINT2D *p3, POINT2D *result)
Determines the center of the circle defined by the three given points.
Definition: lwalgorithm.c:227
int lw_arc_is_pt(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3)
Returns true if arc A is actually a point (all vertices are the same) .
Definition: lwalgorithm.c:105
int mode
Definition: measures.h:54
POINT2D p1
Definition: measures.h:52
double x
Definition: liblwgeom.h:328
int p2d_same(const POINT2D *p1, const POINT2D *p2)
Definition: lwalgorithm.c:49
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
int lw_dist2d_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B, DISTPTS *dl)
lw_dist2d_comp from p to line A->B This one is now sending every occation to lw_dist2d_pt_pt Before i...
Definition: measures.c:2205
POINT2D p2
Definition: measures.h:53
double y
Definition: liblwgeom.h:328
int lw_pt_in_arc(const POINT2D *P, const POINT2D *A1, const POINT2D *A2, const POINT2D *A3)
Returns true if P is on the same side of the plane partition defined by A1/A3 as A2 is...
Definition: lwalgorithm.c:85
double distance
Definition: measures.h:51
double distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2)
The old function nessecary for ptarray_segmentize2d in ptarray.c.
Definition: measures.c:2317
#define FP_EQUALS(A, B)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
int lw_dist2d_pt_pt(const POINT2D *thep1, const POINT2D *thep2, DISTPTS *dl)
Compares incomming points and stores the points closest to each other or most far away from each othe...
Definition: measures.c:2281
Here is the call graph for this function:
Here is the caller graph for this function: