mirror of
https://github.com/unity-atoms/unity-atoms.git
synced 2025-01-24 00:58:59 -05:00
7763f81ede
* Unified all line endings in project to align with .editorconfig; all end-of-line characters have been set to LF and new-lines placed at the end of every file if not present.
24 lines
799 B
C#
24 lines
799 B
C#
using UnityEngine;
|
|
|
|
namespace UnityAtoms.Utils
|
|
{
|
|
public static class Vector2Utils
|
|
{
|
|
// Find out if two lines intersect
|
|
public static bool IsIntersectingAlternative(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4)
|
|
{
|
|
float denominator = (p4.y - p3.y) * (p2.x - p1.x) - (p4.x - p3.x) * (p2.y - p1.y);
|
|
if (denominator != 0)
|
|
{
|
|
float u_a = ((p4.x - p3.x) * (p1.y - p3.y) - (p4.y - p3.y) * (p1.x - p3.x)) / denominator;
|
|
float u_b = ((p2.x - p1.x) * (p1.y - p3.y) - (p2.y - p1.y) * (p1.x - p3.x)) / denominator;
|
|
if (u_a >= 0 && u_a <= 1 && u_b >= 0 && u_b <= 1)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
}
|