PostGIS  3.4.0dev-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 987 of file lwlinearreferencing.c.

988 {
989  POINT3DZ pv; /* velocity of p, aka u */
990  POINT3DZ qv; /* velocity of q, aka v */
991  POINT3DZ dv; /* velocity difference */
992  POINT3DZ w0; /* vector between first points */
993 
994  /*
995  lwnotice("FROM %g,%g,%g,%g -- %g,%g,%g,%g",
996  p0->x, p0->y, p0->z, p0->m,
997  p1->x, p1->y, p1->z, p1->m);
998  lwnotice(" TO %g,%g,%g,%g -- %g,%g,%g,%g",
999  q0->x, q0->y, q0->z, q0->m,
1000  q1->x, q1->y, q1->z, q1->m);
1001  */
1002 
1003  /* PV aka U */
1004  pv.x = (p1->x - p0->x);
1005  pv.y = (p1->y - p0->y);
1006  pv.z = (p1->z - p0->z);
1007  /*lwnotice("PV: %g, %g, %g", pv.x, pv.y, pv.z);*/
1008 
1009  /* QV aka V */
1010  qv.x = (q1->x - q0->x);
1011  qv.y = (q1->y - q0->y);
1012  qv.z = (q1->z - q0->z);
1013  /*lwnotice("QV: %g, %g, %g", qv.x, qv.y, qv.z);*/
1014 
1015  dv.x = pv.x - qv.x;
1016  dv.y = pv.y - qv.y;
1017  dv.z = pv.z - qv.z;
1018  /*lwnotice("DV: %g, %g, %g", dv.x, dv.y, dv.z);*/
1019 
1020  double dv2 = DOT(dv, dv);
1021  /*lwnotice("DOT: %g", dv2);*/
1022 
1023  if (dv2 == 0.0)
1024  {
1025  /* Distance is the same at any time, we pick the earliest */
1026  return t0;
1027  }
1028 
1029  /* Distance at any given time, with t0 */
1030  w0.x = (p0->x - q0->x);
1031  w0.y = (p0->y - q0->y);
1032  w0.z = (p0->z - q0->z);
1033 
1034  /*lwnotice("W0: %g, %g, %g", w0.x, w0.y, w0.z);*/
1035 
1036  /* Check that at distance dt w0 is distance */
1037 
1038  /* This is the fraction of measure difference */
1039  double t = -DOT(w0, dv) / dv2;
1040  /*lwnotice("CLOSEST TIME (fraction): %g", t);*/
1041 
1042  if (t > 1.0)
1043  {
1044  /* Getting closer as we move to the end */
1045  /*lwnotice("Converging");*/
1046  t = 1;
1047  }
1048  else if (t < 0.0)
1049  {
1050  /*lwnotice("Diverging");*/
1051  t = 0;
1052  }
1053 
1054  /* Interpolate the actual points now */
1055 
1056  p0->x += pv.x * t;
1057  p0->y += pv.y * t;
1058  p0->z += pv.z * t;
1059 
1060  q0->x += qv.x * t;
1061  q0->y += qv.y * t;
1062  q0->z += qv.z * t;
1063 
1064  t = t0 + (t1 - t0) * t;
1065  /*lwnotice("CLOSEST TIME (real): %g", t);*/
1066 
1067  return t;
1068 }
#define DOT(u, v)
Definition: measures3d.h:31
double z
Definition: liblwgeom.h:396
double x
Definition: liblwgeom.h:396
double y
Definition: liblwgeom.h:396
double x
Definition: liblwgeom.h:414
double z
Definition: liblwgeom.h:414
double y
Definition: liblwgeom.h:414

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: