PostGIS  2.3.7dev-r@@SVN_REVISION@@
static double segments_tcpa ( POINT4D p0,
const POINT4D p1,
POINT4D q0,
const POINT4D q1,
double  t0,
double  t1 
)
static

Definition at line 907 of file lwlinearreferencing.c.

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

Referenced by lwgeom_cpa_within(), and lwgeom_tcpa().

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

Here is the caller graph for this function: