PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ pt_continues_arc()

static int pt_continues_arc ( const POINT4D a1,
const POINT4D a2,
const POINT4D a3,
const POINT4D b 
)
static

Returns LW_TRUE if b is on the arc formed by a1/a2/a3, but not within that portion already described by a1/a2/a3.

Definition at line 799 of file lwstroke.c.

References distance2d_pt_pt(), EPSILON_SQLMM, lw_arc_angle(), lw_arc_center(), LW_FALSE, lw_segment_side(), LW_TRUE, and LWDEBUGF.

Referenced by pta_unstroke().

800 {
801  POINT2D center;
802  POINT2D *t1 = (POINT2D*)a1;
803  POINT2D *t2 = (POINT2D*)a2;
804  POINT2D *t3 = (POINT2D*)a3;
805  POINT2D *tb = (POINT2D*)b;
806  double radius = lw_arc_center(t1, t2, t3, &center);
807  double b_distance, diff;
808 
809  /* Co-linear a1/a2/a3 */
810  if ( radius < 0.0 )
811  return LW_FALSE;
812 
813  b_distance = distance2d_pt_pt(tb, &center);
814  diff = fabs(radius - b_distance);
815  LWDEBUGF(4, "circle_radius=%g, b_distance=%g, diff=%g, percentage=%g", radius, b_distance, diff, diff/radius);
816 
817  /* Is the point b on the circle? */
818  if ( diff < EPSILON_SQLMM )
819  {
820  int a2_side = lw_segment_side(t1, t3, t2);
821  int b_side = lw_segment_side(t1, t3, tb);
822  double angle1 = lw_arc_angle(t1, t2, t3);
823  double angle2 = lw_arc_angle(t2, t3, tb);
824 
825  /* Is the angle similar to the previous one ? */
826  diff = fabs(angle1 - angle2);
827  LWDEBUGF(4, " angle1: %g, angle2: %g, diff:%g", angle1, angle2, diff);
828  if ( diff > EPSILON_SQLMM )
829  {
830  return LW_FALSE;
831  }
832 
833  /* Is the point b on the same side of a1/a3 as the mid-point a2 is? */
834  /* If not, it's in the unbounded part of the circle, so it continues the arc, return true. */
835  if ( b_side != a2_side )
836  return LW_TRUE;
837  }
838  return LW_FALSE;
839 }
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
static double lw_arc_angle(const POINT2D *a, const POINT2D *b, const POINT2D *c)
Return ABC angle in radians TODO: move to lwalgorithm.
Definition: lwstroke.c:777
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 LW_FALSE
Definition: liblwgeom.h:77
#define EPSILON_SQLMM
Tolerance used to determine equality.
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
int lw_segment_side(const POINT2D *p1, const POINT2D *p2, const POINT2D *q)
lw_segment_side()
Definition: lwalgorithm.c:64
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
Here is the call graph for this function:
Here is the caller graph for this function: