Finds the two closest points on two linesegments.
1174{
1176 double s1k, s2k;
1177
1179 double a, b, c, d, e, D;
1180
1181
1183 {
1185 }
1186
1188 {
1191 }
1192
1194 {
1196 dl->
p1 = dl->
p2 = *s2p1;
1198 }
1199
1200
1201
1202
1203
1204
1207
1210
1213
1219 D = a * c - b * b;
1220
1221 if (D < 0.000000001)
1222 {
1223 s1k =
1224 0.0;
1225
1226 if (b > c)
1227 s2k = d / b;
1228 else
1229 s2k = e / c;
1230 }
1231 else
1232 {
1233 s1k = (b * e - c * d) / D;
1234 s2k = (a * e - b * d) / D;
1235 }
1236
1237
1238
1239
1240 if (s1k <= 0.0 || s1k >= 1.0 || s2k <= 0.0 || s2k >= 1.0)
1241 {
1242 if (s1k <= 0.0)
1243 {
1246 }
1247 if (s1k >= 1.0)
1248 {
1251 }
1252 if (s2k <= 0.0)
1253 {
1257 }
1258 if (s2k >= 1.0)
1259 {
1263 }
1264 }
1265 else
1266 {
1267 p1.
x = s1p1->x + s1k * (s1p2->x - s1p1->x);
1268 p1.
y = s1p1->y + s1k * (s1p2->y - s1p1->y);
1269 p1.
z = s1p1->z + s1k * (s1p2->z - s1p1->z);
1270
1271 p2.
x = s2p1->x + s2k * (s2p2->x - s2p1->x);
1272 p2.
y = s2p1->y + s2k * (s2p2->y - s2p1->y);
1273 p2.
z = s2p1->z + s2k * (s2p2->z - s2p1->z);
1274
1276 {
1278 }
1279 }
1281}
#define LW_TRUE
Return types for functions with status returns.
int p3dz_same(const POINT3DZ *p1, const POINT3DZ *p2)
int lw_dist3d_pt_pt(const POINT3DZ *thep1, const POINT3DZ *thep2, DISTPTS3D *dl)
Compares incoming points and stores the points closest to each other or most far away from each other...
static int get_3dvector_from_points(const POINT3DZ *p1, const POINT3DZ *p2, VECTOR3D *v)
int lw_dist3d_pt_seg(const POINT3DZ *p, const POINT3DZ *A, const POINT3DZ *B, DISTPTS3D *dl)
If searching for min distance, this one finds the closest point on segment A-B from p.