Exemple #1
0
		public static bool RayToRayDistance(Vector3 r1st, Vector3 r1dir, Vector3 r2st, Vector3 r2dir, out Vector3 closestPosOnR1, out float dist)
		{
			Vector3 ortho = r1dir % r2dir;
			float a = ortho | r1st;
			float b = ortho | r2st;

			Vector3 ortho2 = ortho % r2dir;
			ortho2.Normalize();
			Plane pl = new Plane(ortho2, 0.0f);
			pl.CalcDist(r2st);

			float t;
			if (!pl.RayPlaneIntersection(r1st, r1dir, out closestPosOnR1, out t)) {
				dist = 0.0f;
				return false;
			}

			dist = Math.Abs(a - b);
			return true;
		}