public bool Intersect(VectorGeneric2 vector, out Vector2 result) { var intersection = Vector2.zero; var source = new Straight { Origin = vector.Origin, Direction = vector.Target - vector.Origin }; if (!source.Intersect(this, out result)) { return(false); } return(Vector3.Dot( Vector3.Cross(Origin - intersection, Vector3.forward).normalized, Vector3.Cross(Target - intersection, Vector3.forward).normalized) > 0); }
public static bool GetIntersectionInParentSpace(this RectTransform source, Straight cutting, out VectorGeneric2 result) { var intersections = source.GetSidesInParentSpace().Aggregate(new List <Vector2>(2), (acm, _) => { Vector2 intersection; if (cutting.Intersect(_, out intersection)) { acm.Add(intersection); } return(acm); }).ToArray(); //var points = source.GetSidesInParentSpace().Select(_ => _.Origin).ToArray(); //Debug.Log(string.Format("<color=blue>PARENT points: {0}, {1}, {2}, {3},</color>", points[0], points[1], points[2], points[3] )); result = intersections.Length == 0 ? new VectorGeneric2() : new VectorGeneric2 { Origin = Vector2.Dot(cutting.Direction, intersections[1] - intersections[0]) > 0f ? intersections[0] : intersections[1], Target = Vector2.Dot(cutting.Direction, intersections[1] - intersections[0]) > 0f ? intersections[1] : intersections[0] }; return(intersections.Length != 0); }