| 1277 | } |
| 1278 | |
| 1279 | static void NearestPoint(float& t1, float& t2, Vector3Val b1, Vector3Val d1, Vector3Val b2, Vector3Val d2) |
| 1280 | { |
| 1281 | // Finds t1,t2 such that (b1+d1*t1 - b2-d2*t2) is perpendicular to both directions. |
| 1282 | // Note: untested; results may be unreliable on degenerate inputs. |
| 1283 | Vector3 b = b1 - b2; |
| 1284 | float d2d2 = d2 * d2; |
| 1285 | float d1d1 = d1 * d1; |
| 1286 | float d1d2 = d1 * d2; |
| 1287 | float denom = d1d1 * d2d2 - d1d2 * d1d2; |
| 1288 | float bd2 = b * d2; |
| 1289 | float bd1 = b * d1; |
| 1290 | t1 = t2 = 0; |
| 1291 | if (fabs(denom) > 1e-5) // for parallel any t1 will do |
| 1292 | { // not parallel |
| 1293 | t1 = (d1d2 * bd2 - bd1 * d2d2) / denom; |
| 1294 | } |
| 1295 | if (d2d2 > 1e-5) |
| 1296 | { // t2 can be solved |
| 1297 | t2 = (bd2 + d1d2 * t1) / d2d2; |
| 1298 | } |
| 1299 | } |
| 1300 | |
| 1301 | static float NearestPoint(Vector3Val b1, Vector3Val d1, Vector3Val b2, Vector3Val d2) |
| 1302 | { |
no test coverage detected