PostGIS  2.2.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 893 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().

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

Here is the caller graph for this function: