PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ segments_tcpa()

static double segments_tcpa ( POINT4D p0,
const POINT4D p1,
POINT4D q0,
const POINT4D q1,
double  t0,
double  t1 
)
static

Definition at line 912 of file lwlinearreferencing.c.

915 {
916  POINT3DZ pv; /* velocity of p, aka u */
917  POINT3DZ qv; /* velocity of q, aka v */
918  POINT3DZ dv; /* velocity difference */
919  POINT3DZ w0; /* vector between first points */
920 
921  /*
922  lwnotice("FROM %g,%g,%g,%g -- %g,%g,%g,%g",
923  p0->x, p0->y, p0->z, p0->m,
924  p1->x, p1->y, p1->z, p1->m);
925  lwnotice(" TO %g,%g,%g,%g -- %g,%g,%g,%g",
926  q0->x, q0->y, q0->z, q0->m,
927  q1->x, q1->y, q1->z, q1->m);
928  */
929 
930  /* PV aka U */
931  pv.x = ( p1->x - p0->x );
932  pv.y = ( p1->y - p0->y );
933  pv.z = ( p1->z - p0->z );
934  /*lwnotice("PV: %g, %g, %g", pv.x, pv.y, pv.z);*/
935 
936  /* QV aka V */
937  qv.x = ( q1->x - q0->x );
938  qv.y = ( q1->y - q0->y );
939  qv.z = ( q1->z - q0->z );
940  /*lwnotice("QV: %g, %g, %g", qv.x, qv.y, qv.z);*/
941 
942  dv.x = pv.x - qv.x;
943  dv.y = pv.y - qv.y;
944  dv.z = pv.z - qv.z;
945  /*lwnotice("DV: %g, %g, %g", dv.x, dv.y, dv.z);*/
946 
947  double dv2 = DOT(dv,dv);
948  /*lwnotice("DOT: %g", dv2);*/
949 
950  if ( dv2 == 0.0 )
951  {
952  /* Distance is the same at any time, we pick the earliest */
953  return t0;
954  }
955 
956  /* Distance at any given time, with t0 */
957  w0.x = ( p0->x - q0->x );
958  w0.y = ( p0->y - q0->y );
959  w0.z = ( p0->z - q0->z );
960 
961  /*lwnotice("W0: %g, %g, %g", w0.x, w0.y, w0.z);*/
962 
963  /* Check that at distance dt w0 is distance */
964 
965  /* This is the fraction of measure difference */
966  double t = -DOT(w0,dv) / dv2;
967  /*lwnotice("CLOSEST TIME (fraction): %g", t);*/
968 
969  if ( t > 1.0 )
970  {
971  /* Getting closer as we move to the end */
972  /*lwnotice("Converging");*/
973  t = 1;
974  }
975  else if ( t < 0.0 )
976  {
977  /*lwnotice("Diverging");*/
978  t = 0;
979  }
980 
981  /* Interpolate the actual points now */
982 
983  p0->x += pv.x * t;
984  p0->y += pv.y * t;
985  p0->z += pv.z * t;
986 
987  q0->x += qv.x * t;
988  q0->y += qv.y * t;
989  q0->z += qv.z * t;
990 
991  t = t0 + (t1 - t0) * t;
992  /*lwnotice("CLOSEST TIME (real): %g", t);*/
993 
994  return t;
995 }
#define DOT(u, v)
Definition: measures3d.h:31
double z
Definition: liblwgeom.h:337
double x
Definition: liblwgeom.h:337
double y
Definition: liblwgeom.h:337
double x
Definition: liblwgeom.h:355
double z
Definition: liblwgeom.h:355
double y
Definition: liblwgeom.h:355

References DOT, POINT3DZ::x, POINT4D::x, POINT3DZ::y, POINT4D::y, POINT3DZ::z, and POINT4D::z.

Referenced by lwgeom_cpa_within(), and lwgeom_tcpa().

Here is the caller graph for this function: