PostGIS 3.7.0dev-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 975 of file lwlinearreferencing.c.

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