Pathfinding.Polygon.IntersectionFactorRaySegment C# (CSharp) Method

IntersectionFactorRaySegment() public static method

public static IntersectionFactorRaySegment ( Int3 start1, Int3 end1, Int3 start2, Int3 end2 ) : bool
start1 Int3
end1 Int3
start2 Int3
end2 Int3
return bool
		public static bool IntersectionFactorRaySegment (Int3 start1, Int3 end1, Int3 start2, Int3 end2) {
			
			Int3 dir1 = end1-start1;
			Int3 dir2 = end2-start2;
			
			//Color rnd = new Color (Random.value,Random.value,Random.value);
			//Debug.DrawRay (start1,dir1,rnd);
			//Debug.DrawRay (start2,dir2,rnd);
			
			long den = dir2.z*dir1.x - dir2.x * dir1.z;
			
			if (den == 0) {
				return false;
			}
			
			long nom = dir2.x*(start1.z-start2.z)- dir2.z*(start1.x-start2.x);
			long nom2 = dir1.x*(start1.z-start2.z) - dir1.z * (start1.x - start2.x);
			
			//factor1 < 0
			// If both have the same sign, then nom/den < 0 and thus the segment cuts the ray before the ray starts
			if (!(nom < 0 ^ den < 0)) {
				return false;
			}
			
			//factor2 < 0
			if(!(nom2 < 0 ^ den < 0)) {
				return false;
			}
			
			if ((den >= 0 && nom2 > den) || (den < 0 && nom2 <= den)) {
				return false;
			}
			//factor1 = (float)nom/den;
			//factor2 = (float)nom2/den;
			return true;
			
			//Debug.DrawLine (start2,end2,Color.magenta);
			//Debug.DrawRay (start1,dir1*5,Color.green);
		}