Files
XRLib/Assets/Runtime Transform Gizmos/Scripts/Runtime Package Common/Math/Primitive Math/PlaneMath.cs
2025-12-08 10:59:29 +09:00

21 lines
525 B
C#

using UnityEngine;
namespace RTG
{
public static class PlaneMath
{
public static bool Raycast2D(Vector2 rayOrigin, Vector2 rayDir, Vector2 planeNormal, Vector2 ptOnPlane, out float t)
{
t = 0.0f;
float dirPrj = Vector2.Dot(rayDir, planeNormal);
if (Mathf.Abs(dirPrj) < 1e-5f) return false;
float originDist = Vector2.Dot((rayOrigin - ptOnPlane), planeNormal);
t = originDist / -dirPrj;
return t >= 0.0f;
}
}
}