mirror of
https://github.com/unity-atoms/unity-atoms.git
synced 2025-01-24 09:08:23 -05:00
25 lines
882 B
C#
25 lines
882 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
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;
|
|
}
|
|
}
|
|
} |