PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ segments_tcpa()

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

Definition at line 981 of file lwlinearreferencing.c.

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

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: