Test Segments Crossing
public text v1 · immutableusing UnityEngine;
struct Geometry
{
public static bool CrossSegments(Vector2 p0, Vector2 p1, Vector2 q0, Vector2 q1)
{
return AboveSegment(p0, p1, q0) ^ AboveSegment(p0, p1, q1) &&
AboveSegment(q0, q1, p0) ^ AboveSegment(q0, q1, p1);
}
public static bool AboveSegment(Vector3 p0, Vector3 p1, Vector3 q)
{
return p1.x * q.y - q.x * p1.y + q.x * p0.y - p0.x * q.y + p0.x * p1.y - p1.x * p0.y > 0;
}
}