All pastes #1818585 Raw Edit

Test Segments Crossing

public text v1 · immutable
#1818585 ·published 2010-03-02 06:19 UTC
rendered paste body
using 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;
	}
}