PostGIS  2.5.0dev-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 906 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().

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